原文: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