TypeError: can only assign an iterable


在python中,使用List[0:2] = ‘z’,不會產生任何的錯誤,就是讓這List左起第0,1兩個元素賦值為‘z’一個元素;這是因為String字符串本身在python里就是一個字符數組,是可以進行迭代操作的。

而List[0:2] = 1中,就會產生錯誤:TypeError: can only assign an iterable

這是因為整型1,不具有迭代能力,它就是一個值而已。因此未來達到目的,應該寫成List[0:2] = (1,)就OK了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 TypeError: person is not iterable關於for of報錯 TypeError: 'WebElement' object is not iterable [Python] TypeError: only size-1 arrays can be converted to Python scalars Vue的報錯:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' python踩坑記: TypeError: can only concatenate str (not "int") to str 函數錯誤TypeError 'function' object is not iterable Python2.7安裝OpenCV錯誤:TypeError: ‘NoneType’ object is not iterable TypeError: cannot unpack non-iterable NoneType object問題 TypeError: argument of type ‘WindowsPath‘ is not iterable - in django python [duplicate] 解決 Cannot assign to read only property 'exports' of object '#' 問題
 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM