问题
I can do
>>> s = {1}
>>> type(s)
<class 'set'>
but
>>> s = set(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
what is the difference?
回答1:
The difference is that the set()
constructor takes an iterable. A single number is not an iterable.
s = set((1,))
来源:https://stackoverflow.com/questions/27180659/build-a-set-fails-when-using-setint-python