Python问题:'Nonetype' object is not iterable
参考链接:http://blog.csdn.net/dataspark/article/details/9953225
【解析】
这个错误提示一般发生在将None赋给多个值时。
【案例】
定义了如下的函数
def test():
if value == 1:
a = b = 1
return a,b value = 0
a,b = test()
执行这段测试程序会报错:"TypeError: 'NoneType' object is not iterable"
这里是没有考虑到else的情况,在if条件不满足时,函数默认返回None。
调用时,将None赋给 a,b
等价于 a,b = None
就出现了这样的错误提示。
【结论】
1. 将None赋给多个值时,会出现提示:TypeError: 'NoneType' object is not iterable
2. 函数返回值一定要考虑到条件分支的覆盖
3. 在没有return语句时,python默认会返回None
Python问题:'Nonetype' object is not iterable的更多相关文章
- python"TypeError: 'NoneType' object is not iterable"错误解析
尊重原创博主,原文链接:https://blog.csdn.net/dataspark/article/details/9953225 [解析] 一般是函数返回值为None,并被赋给了多个变量. 实例 ...
- 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报错Nonetype object is not iterable
https://www.cnblogs.com/zhaijiahui/p/8391701.html 参考链接:http://blog.csdn.net/dataspark/article/detail ...
- 'NoneType' object is not iterable
"TypeError: 'NoneType' object is not iterable" 一般是返回值为None同时赋值给了多个变量
- python pip 'nonetype' object has no attribute 'bytes'
python pip 'nonetype' object has no attribute 'bytes' 更新 pip for Windows : python -m pip install -U ...
- Python : TypeError: 'int' object is not iterable
用循环依次对list中的每个名字打印出 Hello, xxx! -------------------------------------------------------- L = ['Bart' ...
- python 错误:"'NoneType' object has no attribute 'execute'"
这种原因常常是数据库链接产生的错误,检查连接参数时候齐全,cursor是否获取到了.
- 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提示AttributeError: 'NoneType' object has no attribute 'append'【转发】
在写python脚本时遇到AttributeError: 'NoneType' object has no attribute 'append' a=[] b=[1,2,3,4] a = a.appe ...
随机推荐
- request的基本应用
一.安装 pip install requests (mac前面加sudo) 二.requests的一些参数 method:一般是用的那种请求方法,是get还是post,delete或者delete ...
- vertical-align垂直对齐用法
一.垂直对齐方式{vertical-align:middle/top/bottom:} <img>垂直对齐方式:1)给自身加vertical-align:再设置line-height即可: ...
- spring的设计模式
spring中用到哪些设计模式 1.工厂模式,这个很明显,在各种BeanFactory以及ApplicationContext创建中都用到了: 2.模版模式,这个也很明显,在各种BeanFacto ...
- ES6(promise)_解决回调嵌套简单应用
一.前言 这个小案例是在node平台上应用的所以需要保证你的电脑: 1.安装和配置node.js环境 2.需要用node.js来开启一个http-server: 开启方法:https://blog.c ...
- 因子分析factor analysis_spss运用_python建模(推荐AAA)
sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...
- Spring_事务管理
转自:https://www.ibm.com/developerworks/cn/java/j-master-spring-transactional-use/index.html 事务管理是应用系统 ...
- HDFS 读写数据流程
一.上传数据 二.下载数据 三.读写时的节点位置选择 1.网络节点距离(机架感知) 下图中: client 到 DN1 的距离为 4 client 到 NN 的距离为 3 DN1 到 DN2 的距离为 ...
- JDBC-DbUtils
依赖 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns=" ...
- SonarQube(代码质量管理)环境搭建
继 Centos6.6安装Subversion版本控制工具(Subversion + Apache + jsvnadmin) 后,搭建代码质量管理环境 IP:10.0.210.112 环境:Cento ...
- layui(八)——轮播图常见用法总结
carousel 是 layui 2.0 版本中新增的全新模块,主要适用于跑马灯/轮播等交互场景.它可以满足任何类型内容的轮播式切换操作,更可以胜任 FullPage (全屏上下轮播)的需求,简洁而不 ...