问题描述
背景:
- 在 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.youkuaiyun.com/weixin_40928559/article/details/107694027