参考链接: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的更多相关文章

  1. python"TypeError: 'NoneType' object is not iterable"错误解析

    尊重原创博主,原文链接:https://blog.csdn.net/dataspark/article/details/9953225 [解析] 一般是函数返回值为None,并被赋给了多个变量. 实例 ...

  2. 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', '')) > ...

  3. python报错Nonetype object is not iterable

    https://www.cnblogs.com/zhaijiahui/p/8391701.html 参考链接:http://blog.csdn.net/dataspark/article/detail ...

  4. 'NoneType' object is not iterable

    "TypeError: 'NoneType' object is not iterable" 一般是返回值为None同时赋值给了多个变量

  5. python pip 'nonetype' object has no attribute 'bytes'

    python pip 'nonetype' object has no attribute 'bytes' 更新 pip for Windows : python -m pip install -U ...

  6. Python : TypeError: 'int' object is not iterable

    用循环依次对list中的每个名字打印出 Hello, xxx! -------------------------------------------------------- L = ['Bart' ...

  7. python 错误:"'NoneType' object has no attribute 'execute'"

    这种原因常常是数据库链接产生的错误,检查连接参数时候齐全,cursor是否获取到了.

  8. 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 ...

  9. 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 ...

随机推荐

  1. halcon图像处理的基本思路

    原图素材,1.jpg 过程图: 结果图: 代码及注意事项: read_image (Image, 'C:/Users/Jv/Desktop/1.jpg') rgb1_to_gray (Image, G ...

  2. 4.1、实现4个LED灯同时闪烁

    图中可以看出,P1的0.1.3.4引脚分别连接着4个LED.控制引脚状态,来控制LED. #include "ioCC2530.h" //引用CC2530头文件 /******** ...

  3. keepalived+LVS实现网站负载均衡和HA

    如上图所示,102和103是内网nginx服务器,100和101是边界LB,clinet是1,这个实验是为了实现在LB上虚拟出一个VIP,client通过访问该VIP,来动态负载到两台内网nginx服 ...

  4. linux下创建用户组与用户 只能访问指定目录的方法 以及FTP用户配置详解

    VSFTPD 安装: -- 查看是否已经安装 VSftpd: rpm -qa | grep vsftp yum install -y vsftpd groupadd ftpuser #创建ftpuse ...

  5. 将 数据库中的结果集转换为json格式(三)

    从数据库中得到结果集 public String list() throws Exception { Connection con = null; PageBean pageBean = new Pa ...

  6. nginx配置模板问题404

    nginx配置模板问题 一.nginx主配置文件如下 cat /etc/nginx/nginx.conf user nginx; worker_processes ; #error_log logs/ ...

  7. Memcached入门学习

    Memcached入门学习 学习网址:http://www.runoob.com/Memcached/Memcached-tutorial.html

  8. Sublime Text3 里使用MarkDown如何预览

    安装需要的包: 1.markdown editing 2.markdown preview 具体的步骤是: 1.按住ctrl + shift + p 来调出一个弹出的输入框 :2.输入package  ...

  9. Redis之RDB与AOF 笔记

    AOF定义:以日志的形式记录每个操作,将Redis执行过的所有指令全部记录下来(读操作不记录),只许追加文件但不可以修改文件,Redis启动时会读取AOF配置文件重构数据 换句话说,就是Redis重启 ...

  10. linux 精简开机自启动

    centos7 精简开机自启动 ntsysv rsyslog  crond  sshd network