Python报错:TypeError: 'type' object is not subscriptable

1.Python报错:TypeError: 'type' object is not subscriptable (直译为,类型错误:“类型”对象不可下标)



2.示例代码
1 list=[1,2,3,4,5]
2 def fn(x):
3     return x**2
4 
5 res = map[fn,list]
6 res = [i for i in res if i > 10]
7 print(res)

 3.报错原因

 map函数是小括号,不是中括号

   修改:第5行代码res = map[fn,list],中括号改成小括号,即res = map(fn,list) 
posted @ 2022-02-24 11:15  Gonnago  阅读(16431)  评论(0)    收藏  举报