python"TypeError: 'NoneType' object is not iterable"错误解析
尊重原创博主,原文链接:https://blog.csdn.net/dataspark/article/details/9953225
【解析】
一般是函数返回值为None,并被赋给了多个变量。
实例看下:
c=0
def test():
if c == 1:
a = b = 1
return a, b a, b = test()
使用 a, b = test()调用时,就会报错:TypeError: 'NoneType' object is not iterable
在Python判断语句中,当if条件不满足并且没有else的时候就会返回None,就算是没有return 也会默认返回None
本例中a,b 都赋予了None值,就出现了上述错误。
所以函数返回值一定要考虑到条件分支的覆盖。
本人是正在读的学生,如有错误还请各路大神慷慨指出,谢谢!
python"TypeError: 'NoneType' object is not iterable"错误解析的更多相关文章
- 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', '')) > ...
- Python : TypeError: 'int' object is not iterable
用循环依次对list中的每个名字打印出 Hello, xxx! -------------------------------------------------------- L = ['Bart' ...
- append导致TypeError: 'NoneType' object is not iterable
a=[1,2,3] a.append(4) a Out[4]: [1, 2, 3, 4] a=a.append(5) print(a) None a =[1,2,3] print(a.append(4 ...
- Python问题:'Nonetype' object is not iterable
参考链接:http://blog.csdn.net/dataspark/article/details/9953225 [解析] 这个错误提示一般发生在将None赋给多个值时. [案例] 定义了如下的 ...
- 'NoneType' object is not iterable
"TypeError: 'NoneType' object is not iterable" 一般是返回值为None同时赋值给了多个变量
- TypeError: 'NoneType' object is not subscriptable
运行,显示TypeError: 'NoneType' object is not subscriptable错误信息,原因是变量使用了系统内置的关键字list 重新定义下这个变量就好了
- python报错Nonetype object is not iterable
https://www.cnblogs.com/zhaijiahui/p/8391701.html 参考链接:http://blog.csdn.net/dataspark/article/detail ...
- TypeError: 'TestCase' object is not iterable
这个异常呢其实是因为我对list没有足够熟悉 我一开始很疑惑,明明已经正确返回testcase对象了呀,为啥会报TypeError: 'TestCase' object is not iterable ...
- TypeError: 'ExcelData' object is not iterable
今天写了个测试的代码,结果在执行test_register.py文件在调用readexcle.py的时候一直报错TypeError: 'ExcelData' object is not iterabl ...
随机推荐
- python的循环语句
python的循环语句有两种:for 和 while,for循环是对可迭代对象进行迭代并处理,因此for的对象是一个可以迭代的对象,而while循环的条件则是一个布尔值可以是一个返回布尔值的表达式. ...
- jQuery---基本的选择器
基本选择器 名称 用法 描述 ID选择器 $(“#id”); 获取指定ID的元素 类选择器 $(“.class”); 获取同一类class的元素 标签选择器 $(“div”); 获取同一类标签的所有元 ...
- python笔记06
python笔记06 数据类型 上个笔记内容补充 补充 列表 reverse,反转. v1 = [1,2,3111,32,13] print(v1) v1.reverse() print(v1) v1 ...
- HDU1548 奇怪的电梯(bfs求最少)
There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 ...
- 洛谷P1551 亲戚 (并查集模板题)
链接 https://www.luogu.org/problemnew/show/P1551 代码 #include<bits/stdc++.h> using namespace std; ...
- win10子系统ubuntu内的nginx启动问题
需用sudo启动,密码是windows密码.
- Spring Data JPA介绍与简单案例
一.Spring Data JPA介绍 可以理解为JPA规范的再次封装抽象,底层还是使用了Hibernate的JPA技术实现,引用JPQL(Java Persistence Query Languag ...
- JavaScript 闭包浅析
词法作用域 闭包 概念 作用 用法 待续 词法作用域 词法作用域是指一个变量在源码中声明的位置作为它的作用域.同时嵌套的函数可以访问到其外层作用域中声明的变量. 函数中的定义的局部变量只能由函数的内部 ...
- Java基础知识点总结笔记
面向对象的三大特性 继承:一般只能单继承,内部类实现多继承,接口可以多继承 封装:访问权限控制public>protected>包>private内部类也是一种封装 多态:编译时多态 ...
- HTML连载62-固定定位练习、z-index属性
一.固定定位应用场景 1.练习 <!DOCTYPE html> <html lang="en"> <head> <meta charset ...