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'] 。这样的错误

posted @ 2014-07-01 16:46  hanframe  阅读(3664)  评论(0编辑  收藏  举报