【发布时间】:2021-12-22 03:38:04
【问题描述】:
切入正题,下面是会在 PyCharm 中引发错误的示例代码:
list1 = [0] * 5
list1[0] = ''
list2 = [0 for n in range(5)]
list2[0] = ''
PyCharm 然后在第 2 行和第 4 行返回错误,如下所示:
Unexpected type(s):(int, str)Possible type(s):(SupportsIndex, int)(slice, Iterable[int])
运行代码不会导致任何错误,但 PyCharm 在我编码时会不断出现上述消息。我想知道为什么 PyCharm 会给出这个错误,我怎样才能用最干净的代码解决这个问题。谢谢。
编辑:抱歉,示例代码第 3 行的错字已更正。(list2 = [0 for n in range(0)] 应为 list2 = [0 for n in range(5)])
【问题讨论】:
标签: python python-3.x pycharm