Python 出现错误TypeError: ‘NoneType’ object is not iterable解决办法
2019/7/13 23:17:46
本文主要是介绍Python 出现错误TypeError: ‘NoneType’ object is not iterable解决办法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Python 出现错误TypeError: ‘NoneType' object is not iterable解决办法
TypeError: 'NoneType' object is not iterable 这个错误提示一般发生在将None赋给多个值时。
def myprocess(): a == b if a != b: return True, value; flag, val = myprocess()
在判断语句中,当if条件不满足,并且没有else语句时,函数默认返回None。
在没有return语句时,Python也默认会返回None
调用时,将None赋给多个值时,会出现提示:TypeError: 'NoneType' object is not iterable
本例中,flag和val都被赋予了None(因为if条件不满足,所以默认返回None)就出现了这样的错误提示。
所以函数返回值一定要考虑到条件分支的覆盖
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
这篇关于Python 出现错误TypeError: ‘NoneType’ object is not iterable解决办法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python