迭代"/>
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整形不可迭代
发布评论