Python TypeError: ‘NoneType‘ object is not subscriptable

Posted Aspirantlu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python TypeError: ‘NoneType‘ object is not subscriptable相关的知识,希望对你有一定的参考价值。

Python TypeError: ‘NoneType’ object is not subscriptable

分析

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

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

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

总结

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

以上是关于Python TypeError: ‘NoneType‘ object is not subscriptable的主要内容,如果未能解决你的问题,请参考以下文章