原文:TypeError: string indices must be integers, not str

. TypeError: string indices must be integers, not str 字符串类型取第index个字符的时候,应该传入int而不是str。如 view source print a abcdef printa 而不是 print a 更常见的情况是把一个string当成了字典在使用 :should be dict but string id 。这样的错误 ...

2017-09-04 21:23 0 11623 推荐指数:

查看详情

TypeError: string indices must be integers

这个错误意思是字符串的下标一定要是整数出这种错误有多种可能,最形象直接的就是: 有点pyhton基础的都知道下标怎么能是字符串’0’,必须是整数0,1,2,3… ...

Tue Mar 31 17:32:00 CST 2020 0 7606
python报错 TypeError: string indices must be integers

所以在读取字典的时候,最好先判断类型,然后再查看它是否已经有这样的属性: type(mydict) == type({}) #检查不是字典 如果是字典,再看 ...

Sat Aug 25 03:46:00 CST 2018 0 12675
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM