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 ...
随机推荐
- HDU 1880 魔咒词典 (Hash)
魔咒词典 Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- Haproxy 安装初体验
20180916 haproxy Haproxy简介 Haproxy是一款免费的.快速的和稳定的解决方案,提供HA和LB功能,同时对基于TCP的应用和HTTP的应用进行代理,对于流量很大的web站点来 ...
- svn命令使用;
1.将文件checkout到本地目录 svn checkout svn::xxxxxxxx 简写: svn co 2.往版本库中添加新的文件 svn add files 例如:svn add test ...
- python: 反射机制;
import comma def run(): inp = input('请输入要调用的函数').strip(); if hasattr(comma,inp): fun = getattr(comma ...
- oracle 12C版本的下载安装
首先 去官网下载自己需要的oracle对应的操作系统的版本 接受协议后可下载 1 下载解压好后 进入主目录 进行安装 在配置安全更新中把我希望通过My Oracle Support接收安全更新前面的 ...
- 2018ccpc湖南邀请赛后记
第一次出省去打邀请赛,赛前给队友定的目标是打个铜,这样奖金就可以报销我们的伙食费了 5.12 热身赛,ak的心态冲进去,爆零逃出来 (为什么热身赛没有签到题啊),出来一度以为这场比赛要打铁,毕竟老远过 ...
- C++ 文件保存
文件保存: #include <sstream>#include <fstream>using namespace std; /*save to path ./record ...
- CentOS7 图形化方式安装 Oracle 18c 单实例
下载 Oracle 数据库,zip 包 https://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.h ...
- HTTP深入理解
HTTP被设计于二十世纪九十年代初期,是一种可扩展的协议, 它是应用层的协议, 通过TCP,或TLS加密的TCP连接来发送, 理论上任何可靠的传输协议都可以使用. 因其良好的扩展性,时至今日,它不仅被 ...
- layui(二)——layer组件常见用法总结
layer是layui的代表作,功能十分强大,为方便以后快速配置这里对其常见用法做了简单总结 一.常用调用方式 //1.普通消息:alert(content,[options],[yesCallBac ...