【问题标题】:What does this error mean: "TypeError: Parameters to generic types must be types"?这个错误是什么意思:“TypeError:泛型类型的参数必须是类型”?
【发布时间】:2020-03-06 13:57:32
【问题描述】:

我不确定这个错误是什么意思:

TypeError: Parameters to generic types must be types. Got slice(typing.List, <class 'int'>, None).

我正在尝试确认矩阵中是否有给定的单元格/索引。 (在矩阵[[A, B, C], [D, E, F]] 中是否存在单元格/索引[0, 2]?在C 处是)。

我的输入参数是一个指定单元格索引的列表。我想获取单元格/列表并对其进行修改以检查它是否存在。每次我尝试触摸参数列表时,都会报错。​​

def in_matrix(matr: List[List:int], cell: List[int]) -> bool:
    b = cell.pop()
    a = cell.pop()
    print(a)
    print(b)
    for y in range(len(matr)):
        for x in range(len(matr[y])):
            if matr[a][b] == True:
                return True
            else:
                return False

【问题讨论】:

    标签: python python-3.x typeerror


    【解决方案1】:

    这个类型matr: List[List:int]应该是matr: List[List[int]]

    这意味着matr 是一个整数列表的列表,例如:

    matr = [[1, 2, 3],
            [4, 5, 6],
            [7, 8, 9]]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-17
      • 2020-09-10
      • 1970-01-01
      • 2012-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多