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 ...
随机推荐
- Xml一(基本语法和约束)、
XML:eXtensible Markup Language 可扩展标记语言 version="1.0" * 可扩展:所有的标签都是自定义的. * 功能:数据存储 * 配置文件 * ...
- POJ 3249 Test for Job (记忆化搜索)
Test for Job Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 11830 Accepted: 2814 Des ...
- idea 设置console 无1024限制,复制到Excel分隔符\t
在安装目录/bin中找到idea.properties文件, 更改idea.cycle.buffer.size项值为disabled,保存,重启idea Excel分隔符\t; 数字自动加逗号的情况, ...
- centos 7 安装appache 服务器
一.安装Apache程序,一般有三种安装方式:1.直接网络安装:2.下载rpm包,上传至服务器进行安装:3.通过原代码编译安装: yum -y install httpd rpm -qa | grep ...
- mysql 5.7 启动脚本
最近这段时间,在看mysql,安装了,也应用过,对于生产环境中,一般都选择使用source code安装,在安装的时候可以自定义相关路径和内容,对于生产环境来说更有效.相对于mysql 5.5的安装, ...
- Luogu P4070 [SDOI2016]生成魔咒
题目链接 \(Click\) \(Here\) 其实是看后缀数组资料看到这个题目的,但是一眼反应显然后缀自动机,每次维护添加节点后的答案贡献即可,唯一不友好的一点是需要平衡树维护,这里因为复杂度不卡而 ...
- javaSE eclipse tomocat安装与配置
---恢复内容开始--- javaSE 下载: 第一步:百度收索jdk downlaod 下载地址:https://www.oracle.com/technetwork/ja ...
- QImage与cv::Mat转换;
QImage主要格式有QImage::Format_RGB32, QImage::Format_RGB888, QImage::Format_Index8, 不同的格式有不同的排布: 格式部分可以参考 ...
- 剑指Offer_编程题_8
题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法. class Solution { public: int jumpFloor(int number ...
- Matplotlib中柱状图bar使用
一.函数原型 matplotlib.pyplot.bar(left, height, alpha=1, width=0.8, color=, edgecolor=, label=, lw=3) 1. ...