Python : TypeError: 'int' object is not iterable
用循环依次对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的更多相关文章
- python"TypeError: 'NoneType' object is not iterable"错误解析
尊重原创博主,原文链接:https://blog.csdn.net/dataspark/article/details/9953225 [解析] 一般是函数返回值为None,并被赋给了多个变量. 实例 ...
- python TypeError: 'int' object is not callable 问题解决
TypeError: 'int' object is not callable 这个错误的原因很简单 看下面的程序: def loss(a,b): return a-b loss = 0 loss = ...
- 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', '')) > ...
- TypeError: 'TestCase' object is not iterable
这个异常呢其实是因为我对list没有足够熟悉 我一开始很疑惑,明明已经正确返回testcase对象了呀,为啥会报TypeError: 'TestCase' object is not iterable ...
- 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 ...
- python报错:TypeError: 'int' object is not subscriptable
检查一遍报错的所在行,此报错一般是在整数上加了下标: 比如: a = 4 c=a[2] 报错:line 2, in <module> c=a[2] TypeError: 'i ...
- python: "TypeError: 'type' object is not subscriptable"
目前stackoverflow找到两种情况的解决办法: 1.TypeError: 'type' object is not subscriptable when indexing in to a di ...
- TypeError: 'ExcelData' object is not iterable
今天写了个测试的代码,结果在执行test_register.py文件在调用readexcle.py的时候一直报错TypeError: 'ExcelData' object is not iterabl ...
- Debug 路漫漫-11:Python: TypeError: 'generator' object is not subscriptable
调试程序,出现以下错误: Python: TypeError: 'generator' object is not subscriptable “在Python中,这种一边循环一边计算的机制,称为生成 ...
随机推荐
- C++ com 组件的使用
// CommonTest.cpp : This file contains the 'main' function. Program execution begins and ends there. ...
- Redis缓存雪崩、缓存穿透、热点key
转载自 https://blog.csdn.net/wang0112233/article/details/79558612 https://www.sohu.com/a/230787856_231 ...
- 通过PEB的Ldr枚举进程内所有已加载的模块
一.几个重要的数据结构,可以通过windbg的dt命令查看其详细信息 _PEB._PEB_LDR_DATA._LDR_DATA_TABLE_ENTRY 二.技术原理 1.通过fs:[30h]获取当前进 ...
- java 捕获组与非捕获组
非捕获组:格式:(?:xxxx), 如:(?:aaa)\\w+(bbb)\\1,\\1 代表重复捕获的第一组即是(bbb) public static void main(String[] args) ...
- 刷题-力扣-122. 买卖股票的最佳时机 II
122. 买卖股票的最佳时机 II 题目链接 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/best-time-to-buy-and-sell ...
- unitest单元测试TestCase 执行测试用例(一)
前言 unittest单元测试框架不仅可以适用于单元测试,还可以适用自动化测试用例的开发与执行,该测试框架可组织执行测试用例,并且提供了丰富的断言方法,判断测试用例是否通过,最终生成测试结果. uni ...
- 《网页布局基础篇》HTML+CSS单列布局--水平居中,垂直居中,水平垂直居中
https://blog.csdn.net/panlu666_pl/article/details/66480433 一.水平居中 子元素在父元素中水平居中 1.使用 text-align和inlin ...
- Caffe 快速入门笔记
官网:http://caffe.berkeleyvision.org/ 其中包含Notebook Example方便入门学习 只是使用她的库还是比较简单,其难点在于: 安装 源码 训练好的模型,用于迁 ...
- 剑指offer 计划1(栈与队列)---java
1.1.题目1 剑指 Offer 09. 用两个栈实现队列 1.2.解法 解法如题目所说.定义两个栈.这里假设第一个栈为a,第二个栈为b. 实现两个函数增加尾和删除头. 增加即直接push入第一个栈. ...
- 存储系统管理(一)——Linux系统的设备和分区管理
1.设备名称的理解 /dev/sda1? sata硬盘,a1表示第一块硬盘中的第一个分区 /dev/cdrom 光驱 /dev/mapper/*? 系统中的虚拟设备 2.发现系统中的设备 ? fdis ...