问题描述
背景:
- 在 jupyter notebook 中,使用 list() 函数报错:
alist = list([2 , 3, 1, 1, 2, 3, 'a string'])
alist
TypeError Traceback (most recent call last)
Input In [36], in <cell line: 1>()
----> 1 alist = list([2 , 3, 1, 1, 2, 3, 'a string'])
2 alist
TypeError: 'list' object is not callable
具体:


解决方法
说明:
- 原因:前面有变量名称与系统关键字冲突。“list”与最初的列表名称冲突,因此报错。
- 处理:先通过del 将冲突的变量删除,再进行之后的操作
操作:
del list #先删除操作,使用del 冲突的变量(关键字)
alist = list([2 , 3, 1, 1, 2, 3, 'a string'])
alist
[2, 3, 1, 1, 2, 3, 'a string']
如图:

参考:https://blog.csdn.net/weixin_40928559/article/details/107694027
当在Jupyter Notebook中尝试使用`list()`函数时遇到了TypeError,原因是变量名与内置的`list`关键字冲突。解决方法是首先使用`del`语句删除冲突的变量,然后重新定义列表。这样就可以正常创建和使用列表了。

9280

被折叠的 条评论
为什么被折叠?



