出现TypeError: 'int' object is not subscriptable异常的情况与解决方法

出现TypeError: ‘int’ object is not subscriptable异常的情况与解决方法
原因:不支持索引的对象使用索引
例:

l = 2
l[1]

在这里插入图片描述
解决方法:
使用前确认该对象是否支持索引

l = 'abc'
l[1]

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/DansonC/article/details/88860957