Python 出現錯誤TypeError: ‘NoneType’ object is not iterable解決辦法
更新時間:2017年01月12日 10:09:24 投稿:lqh
這篇文章主要介紹了Python 出現錯誤TypeError: ‘NoneType’ object is not iterable解決辦法的相關資料,需要的朋友可以參考下
Python 出現錯誤TypeError: ‘NoneType' object is not iterable解決辦法
TypeError: 'NoneType' object is not iterable 這個錯誤提示一般發(fā)生在將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開發(fā)時報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的示例詳解

