参考链接: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. tomcat发布项目,运行不了

    工作中经常出现项目本来运行得好好的,从SVN上面更新代码后就不行了 这个问题有时候是因为编译不成功,处理步骤如下: 1.clean整个项目,重新编译 2.如果还是不行,则把编译中认为是error的设置 ...

  2. 高级组件——工具栏JToolBar

    import javax.swing.*; import java.awt.*; public class Demo extends JFrame { public Demo() { setTitle ...

  3. linux环境java入门

    1. 安装java开发环境 安装jre和jdk $ sudo apt-get install default-jre$ sudo apt-get install default-jdk 2. 设置环境 ...

  4. (字典序问题) nyoj1542-最小字符串

    题目描述: 给你一个由小写字母组成的字符串,最多删除其中一个字符,使其字典序最小. 字典序概念在数学中,字典或词典顺序(也称为词汇顺序,字典顺序,字母顺序或词典顺序)是基于字母顺序排列的单词按字母顺序 ...

  5. day-03(js)

    回顾: css: 层叠样式表 作用: 渲染页面 提供工作效率,将html和样式分离 和html的整合 方式1:内联样式表 通过标签的style属性 <xxx style="...&qu ...

  6. python自动化开发-[第十天]-线程、协程、socketserver

    今日概要 1.线程 2.协程 3.socketserver 4.基于udp的socket(见第八节) 一.线程 1.threading模块 第一种方法:实例化 import threading imp ...

  7. flask form表单验证

    新建forms.py文件 #!/usr/bin/env python #-*-coding:utf--*- #导入模块 from flask_wtf import FlaskForm #FlaskFo ...

  8. MySQL权限授权认证详解

    MySQL权限授权认证详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL权限系统介绍1>.权限系统的作用是授予来自某个主机的某个用户可以查询.插入.修改.删除 ...

  9. MySQL8常见客户端和启动相关参数

    MySQL8常见客户端和启动相关参数 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL常见的客户端 1>.使用MySQL服务自带的mysql连接工具 2>. ...

  10. JAVA核心技术I---JAVA基础知识(数字相关类)

    一:相关数字类 –整数 Short, Int, Long –浮点数 Float, Double –大数类 BigInteger(大整数), BigDecimal(大浮点数) –随机数类 Random ...