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 ...
随机推荐
- 使用Xpath爬取酷狗TOP500的歌曲信息
使用xpath爬取酷狗TOP500的歌曲信息, 将排名.歌手名.歌曲名.歌曲时长,提取的结果以文件形式保存下来.参考网址:http://www.kugou.com/yy/rank/home/1-888 ...
- MySQL进阶之存储引擎MyISAM与InnoDB的区别
一.存储引擎(表类型) 通常意义上,数据库就是数据的集合,具体到计算机数据库可以是存储器上一些文件的集合或一些内存数据的集合.我们通常说的MySQL数据库.sql Server数据库等其实是数据库管理 ...
- xmind修改默认配置
XMIND使用过程中,输入英文字符的时候,第1.2层级的英文字母总是默认大写,手动修改很繁琐.默认字体,想切换成其他类型,也是要手动一个个去修改. 网上找了下相关的问题,找到一些解决办法,整理到文档中 ...
- zabbix的web界面出现乱码解决方案
1.问题描述:当我们搭建好zabbix服务器后,查看监控信息时,发现数据显示的下端文字显示为乱码. 2.解决方式: (1)拷贝windows系统字体: 可根据各自的喜好进行选择,我这边就选择楷体 常规 ...
- PP: Sequence to sequence learning with neural networks
From google institution; 1. Before this, DNN cannot be used to map sequences to sequences. In this p ...
- linux - mysql:启动 mysql
启动mysql 第一种: /etc/rc.d/init.d/mysqld start /etc/rc.d/init.d/mysqld stop 第二种:使用service 启动.关闭MySQL服务 s ...
- [JSOI2010]快递服务
Description Luogu4046 BZOJ1820 Solution 暴力DP很好想,\(f[i][j][k][l]\)表示处理到第\(i\)个任务,三个人在\(i,j,k\)的方案数.显然 ...
- lnmp1.5一键安装包安装lnmpa后,添加站点
lnmp1.5一键安装包安装lnmpa后,添加站点 (1)添加站点 (2)配置apache配置文件 在/usr/local/apache/conf/vhost文件夹下,修改webApp站点配置文件ap ...
- pandas包学习笔记
目录 zip Importing & exporting data Plotting with pandas Visual exploratory data analysis 折线图 散点图 ...
- pandas模块详解
Pandas模块 1.什么是pandas pandas是基于numpy构建的,用来做数据分析的 2.pandas能干什么 具备对其功能的数据结构DataFrame,Series 集成时间序列功能 提供 ...