我能做到
>>> s = {1}
>>> type(s)
<class 'set'>
但是
>>> s = set(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
有什么区别?
最佳答案
不同之处在于 set()
构造函数采用可迭代对象。单个数字不是可迭代的。
s = set((1,))
关于python - 为什么使用 set(int) 构建集合失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27180659/