范围功能在 jupyter notebook 中不起作用

range function doesn't work in jupyter notebook

我在 vscode 中使用 jupyter notebook。 我在 Jupyter notebook(.ipynb)

中执行简单代码
a = list(range(10))
print(a)

代码执行结果为...

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-27-b9f6d3d8e065> in <module>
----> 1 a = list(range(10))
      2 print(a)

TypeError: 'range' object is not callable

但是,代码在Python文件(.py)

中执行得很好

当然,代码执行结果是...

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

这是一个我不明白的错误。我想避免因为这个问题而无法使用 Jupiter notebook。我请求你的帮助。

您可能已经定义了列表、范围变量,请尝试重新启动您的笔记本。

list = range(10)
>>> list(range(10))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'range' object is not callable