python整形不可迭代

编程入门 行业动态 更新时间:2024-10-08 22:46:05

python整形不可<a href=https://www.elefans.com/category/jswz/34/1770528.html style=迭代"/>

python整形不可迭代

错误说明:“ NoneType”对象不可迭代

在python2中,NoneType是None的类型。在Python3中,NoneType是None的类,例如:

>>> print(type(None))     #Python2

         #In Python2 the type of None is the 'NoneType' type.

>>> print(type(None))     #Python3

        #In Python3, the type of None is the 'NoneType' class.

遍历具有值None的变量失败:

for a in None:

print("k")     #TypeError: 'NoneType' object is not iterable

Python方法如果不返回值,则返回NoneType:

def foo():

print("k")

a, b = foo()      #TypeError: 'NoneType' object is not iterable

您需要像这样检查NoneType的循环结构:

a = None

print(a is None)              #prints True

print(a is not None)          #prints False

print(a == None)              #prints True

print(a !=

更多推荐

python整形不可迭代

本文发布于:2024-03-04 11:40:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1709176.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:迭代   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!