TypeError: 'type' object is not subscriptable while using ->
TypeError: 'type' object is not subscriptable while using ->
写一个简单的class,它有一个返回[0,0]
的方法
class Solution:
def contain(self, nums: list[int], target: int) -> list[int]:
return [0,0]
Solution().contain(nums=[1,2,3,4], target=3)
Traceback (most recent call last):
line 1, in <module>
class Solution:
line 2, in Solution
def contain(self, nums: list[int], target: int) -> list[int]:
TypeError: 'type' object is not subscriptable
if list[int], int 只是占位符为什么代码 运行 当我删除它们时(使用 def contain(self, nums, target):)?
那是因为list
需要List
。看here。您的代码索引类型 list
.
写一个简单的class,它有一个返回[0,0]
的方法 class Solution:
def contain(self, nums: list[int], target: int) -> list[int]:
return [0,0]
Solution().contain(nums=[1,2,3,4], target=3)
Traceback (most recent call last):
line 1, in <module>
class Solution:
line 2, in Solution
def contain(self, nums: list[int], target: int) -> list[int]:
TypeError: 'type' object is not subscriptable
if list[int], int 只是占位符为什么代码 运行 当我删除它们时(使用 def contain(self, nums, target):)?
那是因为list
需要List
。看here。您的代码索引类型 list
.