Python 出现错误TypeError: ‘NoneType’ object is not iterable解决办法
投稿:lqh
这篇文章主要介绍了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: ‘int‘ object is not iterable错误的解决方式
 - Python源码学习之PyType_Type和PyBaseObject_Type详解
 - Python源码学习之PyObject和PyTypeObject
 - python报错TypeError: ‘NoneType‘ object is not subscriptable的解决方法
 - 解决Python 异常TypeError: cannot concatenate ''str'' and ''int'' objects
 - Python:type、object、class与内置类型实例
 - 详解Python中的type和object
 - 最新整理Python中的type和object的示例详解
 
