Python 出現(xiàn)錯誤TypeError: ‘NoneType’ object is not iterable解決辦法
Python 出現(xiàn)錯誤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語句時,函數(shù)默認返回None。
在沒有return語句時,Python也默認會返回None
調用時,將None賦給多個值時,會出現(xiàn)提示:TypeError: 'NoneType' object is not iterable
本例中,flag和val都被賦予了None(因為if條件不滿足,所以默認返回None)就出現(xiàn)了這樣的錯誤提示。
所以函數(shù)返回值一定要考慮到條件分支的覆蓋
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
- 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的示例詳解
相關文章
科學計算NumPy之Ndarray運算函數(shù)操作示例匯總
這篇文章主要為大家介紹了科學計算NumPy之Ndarray運算函數(shù)操作示例匯總,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-04-04