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