TypeError: string indices must be integers, not str


1. TypeError: string indices must be integers, not str

字符串类型取第index个字符的时候,应该传入int而不是str。如

1 a='abcdef'
2 print a[0]
3 #而不是 print a['0']

更常见的情况是把一个string当成了字典在使用 :should_be_dict_but_string['id'] 。这样的错误


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM