参考链接: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. 关于苹果手机微信端 position: fixed定位top导航栏问题

    在移动端,position: fixed定位一般不被识别,或者在ios系统中,获取input焦点时,会导致position: fixed的top失效,下面是我验证过的方法,大家可以试试.<!do ...

  2. (排序的新方法)nyoj1080-年龄排序

    1080-年龄排序 内存限制:234MB 时间限制:2000ms 特判: No通过数:148 提交数:575 难度:0 题目描述: JXB经常向HJS炫耀他们家乡那里有多么多么好,但是HJS大牛从来对 ...

  3. String 中常用的几种方法

    /* String(char[] value)传递字符数组 将字符数组转换为字符串 字符数组不查询编码表 */ public static void fun1(){ char[] ch = {'a', ...

  4. java十进制转三十六进制

    import java.util.HashMap; public class Ten2Thirty { private static final String X36 = "01234567 ...

  5. django 跨域解决方案

    使用django-cors-headers模块 github:https://github.com/ottoyiu/django-cors-headers 官方文档中有详细说明 简要配置 1.安装 p ...

  6. 安装FreeIPA以及应用时报错汇总

    安装FreeIPA以及应用时报错汇总 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.ERROR DNS zone yinzhengjie.org.cn already exis ...

  7. oracle数据泵导入导出命令

    1.在PL/SQL的界面,找到Directories文件夹,找到目录文件的路径 2.通过SSH进入服务器 找到相应的路径 cd /u01/oracle/dpdir 输入指令 df -h   查看资源使 ...

  8. Web API中的传参方式

    在Restful风格的WebApi的里面,API服务的增删改查,分别对应着Http Method的Get / Post / Delete /Put,下面简单总结了Get / Post /Delete ...

  9. Cannot make a static reference to the non-static

    public class SeckillServiceImpl implements SeckillService{ private SeckillDao seckillDao; private Su ...

  10. 如何在Mac上搭建自己的服务器——Nginx

    1.安装Homebrew 打开终端,输入: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/ ...