参考链接: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. 字符输出流 FileWriter

    FileWriter 方法: writer(); flush(); package cn.lideng.demo3; import java.io.FileWriter; import java.io ...

  2. Nginx入门篇-基础知识与linux下安装操作

    我们要深刻理解学习NG的原理与安装方法,要切合实际结合业务需求,应用场景进行灵活使用. 一.Nginx知识简述Nginx是一个高性能的HTTP服务器和反向代理服务器,也是一个 IMAP/POP3/SM ...

  3. bzoj1027 状压dp

    https://www.lydsy.com/JudgeOnline/problem.php?id=1072 题意 给一个数字串s和正整数d, 统计s有多少种不同的排列能被d整除 试了一下发现暴力可过 ...

  4. CodeForces12D 树状数组降维

    http://codeforces.com/problemset/problem/12/D 题意 给N (N<=500000)个点,每个点有x,y,z ( 0<= x,y,z <=1 ...

  5. 16.Linux-LCD驱动(详解)

    在上一节LCD层次分析中,得出写个LCD驱动入口函数,需要以下4步: 1) 分配一个fb_info结构体: framebuffer_alloc(); 2) 设置fb_info 3) 设置硬件相关的操作 ...

  6. 设计模式_代理模式_在SqlSessionTemplate(Spring)中的应用

    1.SqlSessionTemplate的构造函数,根据传入的SqlSessionFactory和ExecutorType创建一个Spring管理的SqlSession,并生成SqlSession的动 ...

  7. linux 配置本地光盘YUM源

    1.挂载光盘到 /media下 [root@localhost ~]# mount /dev/cdrom /media 2.直接配置文件了. [root@localhost ~]# cd /etc/y ...

  8. MyBatis-Helloworld

    一.依赖配置 1.pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns= ...

  9. Hadoop记录-技术网站

    Grafan监控:http://docs.grafana.org/ Tez:http://tez.apache.org/install.html 阿里巴巴镜像:https://opsx.alibaba ...

  10. Web API中的返回值类型

    WebApi中的返回值类型大致可分为四种: Void/ IHttpActionResult/ HttpResponseMessage /自定义类型 一.Void void申明方法没有返回值,执行成功后 ...