欢迎光临
我们一直在努力

TypeError: ‘NoneType‘ object is not subscriptable 怎么解决?先分清它和 has no attribute 的区别

TypeError: \’NoneType\’ object is not subscriptable 怎么解决?先分清它和 has no attribute 的区别

这个报错的意思是:你对一个 None 用了方括号取值,也就是写了 None[\’key\’]。Python 里 None 不支持下标操作,所以直接抛错。

关键不在报错本身,而在那个变量为什么是 None。下面按真实运行输出来拆,每个场景都附上可以自己敲一遍的代码。

报错:\’NoneType\’ object is not subscriptable
│
▼
看 ~~~~^^^^^ 指向哪个变量

赞(0)
未经允许不得转载:171主机测评 » TypeError: ‘NoneType‘ object is not subscriptable 怎么解决?先分清它和 has no attribute 的区别
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址