Python TypeError: ‘NoneType‘ object is not subscriptable

阅读 168

2022-03-30


Python TypeError: ‘NoneType’ object is not subscriptable

分析

现有一变量 ​​li​​ ,list 类型,通过索引去获取获取value


Python TypeError: ‘NoneType‘ object is not subscriptable_python

是可以取到value,但是如果 ​​li = None​​ ,再通过索引获取value就会报错


Python TypeError: ‘NoneType‘ object is not subscriptable_后端_02

同理,如果变量是dict类型也会出现一样的报错

Python TypeError: ‘NoneType‘ object is not subscriptable_后端_03

总结

对一个值为None的变量,进行索引取值或通过key取值,都会报 ​​'NoneType' object is not subscriptable​​ 错。



精彩评论(0)

0 0 举报