码迷,mamicode.com
首页 > 其他好文 > 详细

TypeError: string indices must be integers, not str

时间:2017-09-04 22:49:50      阅读:633      评论:0      收藏:0      [点我收藏+]

标签:china   ict   错误   should   def   view   source   字典   href   

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

TypeError: string indices must be integers, not str

标签:china   ict   错误   should   def   view   source   字典   href   

原文地址:http://www.cnblogs.com/li134655/p/7475894.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!