>>> thisset =set(("Google","Runoob","Taobao","Facebook"))
>>> y=set({'python'})
>>>print(y.union(thisset))
{'python','Taobao','Google','Facebook','Runoob'}
输出结果:
{'python','Google','Taobao','Facebook','Runoob'}
y 的集合里此时只含有一个元素 'python',而如果不加花括号时,y 的集合里含有'p','y','t','h','o','n'五个元素。
>>> thisset =set(("Google","Runoob","Taobao","Facebook"))
>>> y=set('python')
>>>print(y.union(thisset))
{'p','o','y','Taobao','h','Google','Facebook','Runoob','n','t'}
也可以使用括号:
thisset =set(("Google","Runoob","Taobao","Facebook"))
y=set(('python','love'))
print(y.union(thisset))
输出结果:
{'Facebook','Runoob','Taobao','python','love','Google'}
但是当 y 的集合里只有一个字符串时,结果与不加花括号一样。