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