用循环依次对list中的每个名字打印出 Hello, xxx!

--------------------------------------------------------

L = ['Bart', 'Lisa', 'Adam']
x = len(L)

for i in range(x):

print('Hello,', L[i])

--------------------------------------------------------

 

此处,若直接使用 for i in x 时,编译报错:TypeError: 'int' object is not iterable:

Traceback (most recent call last):
File "main.py", line 5, in <module>
    for i in x:
TypeError: 'int' object is not iterable

该问题的原因是:不能直接用int进行迭代,而必须使用range方法,即range(x).

 

Python : TypeError: 'int' object is not iterable的更多相关文章

  1. python"TypeError: 'NoneType' object is not iterable"错误解析

    尊重原创博主,原文链接:https://blog.csdn.net/dataspark/article/details/9953225 [解析] 一般是函数返回值为None,并被赋给了多个变量. 实例 ...

  2. python TypeError: 'int' object is not callable 问题解决

    TypeError: 'int' object is not callable 这个错误的原因很简单 看下面的程序: def loss(a,b): return a-b loss = 0 loss = ...

  3. python TypeError: 'NoneType' object is not iterable

    list(set(map(lambda tp_id : tp_id if not ('#' in tp_id) and len(tp_id.strip().replace('\n', '')) > ...

  4. TypeError: 'TestCase' object is not iterable

    这个异常呢其实是因为我对list没有足够熟悉 我一开始很疑惑,明明已经正确返回testcase对象了呀,为啥会报TypeError: 'TestCase' object is not iterable ...

  5. for遍历用例数据时,报错:TypeError: list indices must be integers, not dict,'int' object is not iterable解决方法

    一:报错:TypeError: list indices must be integers, not dict for i in range(0,len(test_data)): suite.addT ...

  6. python报错:TypeError: 'int' object is not subscriptable

    检查一遍报错的所在行,此报错一般是在整数上加了下标: 比如:   a = 4   c=a[2] 报错:line 2, in <module>    c=a[2] TypeError: 'i ...

  7. python: "TypeError: 'type' object is not subscriptable"

    目前stackoverflow找到两种情况的解决办法: 1.TypeError: 'type' object is not subscriptable when indexing in to a di ...

  8. TypeError: 'ExcelData' object is not iterable

    今天写了个测试的代码,结果在执行test_register.py文件在调用readexcle.py的时候一直报错TypeError: 'ExcelData' object is not iterabl ...

  9. Debug 路漫漫-11:Python: TypeError: 'generator' object is not subscriptable

    调试程序,出现以下错误: Python: TypeError: 'generator' object is not subscriptable “在Python中,这种一边循环一边计算的机制,称为生成 ...

随机推荐

  1. Ubuntu系统开放指定端口

    今天在一台Ubuntu服务器里面配置了一个Nginx服务,监听的8080端口.本机可以访问,但是局域网就是访问不到.首先怀疑防火墙没有开放8080端口,设置ufw防火墙开放8080端口 $ sudo ...

  2. HttpURLconnection的介绍

    一,HttpURLconnection的介绍 在Android开发中网络请求是最常用的操作之一, Android SDK中对HTTP(超文本传输协议)也提供了很好的支持,这里包括两种接口: 1.标准J ...

  3. Servlet的类加载器

    Java虚拟机中内嵌的一个类加载器:Bootstrap,属于Java虚拟机的内核,负责加载Java核心包中的类(即rt.jar文件中的类):Java核心包中有另外两个类加载器:ExtClassLoad ...

  4. 收下这7款插件,让你在使用 Vite 的时候如虎添翼

    相信已经有不少小伙伴已经开始用 Vue3 做开发了,也一定使用上 Vite 了,而我今天要介绍的这几款插件,能让你在使用 Vite 做开发时如虎添翼. vite-plugin-restart 通过监听 ...

  5. 一、Rabbitmq的简单介绍

    以下只是本人从零学习过程的整理 部分内容参考地址:https://www.cnblogs.com/ysocean/p/9240877.html 1.RabbitMQ的概念 RabbitMQ是实现了高级 ...

  6. 一、自动化监控利器-Zabbix

    目录 1. 监控的作用 1.1 为何需要监控系统 1.2 监控系统的实现 1.3 常用的监控软件 2. Zabbix简介 2.1 选择Zabbix的理由 2.2 Zabbix的功能特性 3. Zabb ...

  7. pycharm 汉化

    1.首先进入pycharm,点击file,找到setting. 2.点击 plugins 搜索Chinese,找到Chinese(simplified)Language Pack EAP,点击inst ...

  8. noip模拟35

    A. 玩游戏 考场做法用双指针向两侧更新,当左段点左移一位时,如果右端点不满足条件,则跳回肯定满足的位置.复杂度玄学 题解做法是类似最长子段和,如果有一个区间和为负,则维护的指针跳过去即可 B. 排列 ...

  9. JS014. toFixed( )调试踩坑 - 浏览器思维 点常量 & 点运算符

    Number.prototype.toFixed( ) 在观察toFixed()丢失精度问题,和对toFixed()方法重写的调试过程时,发现toFixed()对Number的识别有它自己的规则,并找 ...

  10. Vite详解

    vite 目录 一.推荐两个插件插件 Volar Vue 3 Snippets 二.vite简介 优势分析 浏览器支持 三.vite搭建vue3.x项目 1.创建项目 2.集成Vue-Router 3 ...