python2.7 set与list 互相转换

>>> l3
set([2])
>>> l3=list(l3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'list' object is not callable
>>> l3=list(l3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'list' object is not callable
>>> l3
set([2])

我看网上python set 可以转换list 但是我这个怎么不行呢?谢谢

阅读 17.7k
2 个回答

你的代码是什么?

>>> I3=set([2])
>>> I3=list(I3)
>>> print(I3)
[2]

如果是上面这样的,它是没错的

'list' object is not callable

可能的原因是你定义了一个变量叫list, 把系统的关键字覆盖了
试试

>>> print(type(list))
<class 'type'>

感谢上面的答主

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题