为了清楚起见,您需要验证元组
(1, 2)
是在
s
是吗?利用Python对可读性的灵活性可以帮助您理解为什么括号的数量是必要的。
set( # first paren is for calling the function set
( # second paren creates the object of items set should look at
(1,2), # is an item in the set
)
)
# output same as
set(((1,2), (1,2), (1,2)))
# output same as
t = ((1,2), (1,2), (1,2))
set(t)
# output same as
t = (1,2)
t = (t, t, t)
set(t)
# output same as
t = (1, 2)
set([t]*5)
set()
查找中的所有项
self
是的。如果您希望得到比设置变量更可读的解决方案。