python中set结构的函数更新

python中set结构的函数更新,python,functional-programming,set,Python,Functional Programming,Set,python中是否有类似于函数更新的向集合添加元素的方法 myset = set(somelist) myset.add('timestamp') #myset memory location has been mutated to contain 'timestamp' 而我想 myset = set(somelist).add('timestamp') #mutation or not, it's functional for all I care 您可以使用union方法: myse

python中是否有类似于函数更新的向集合添加元素的方法

myset = set(somelist)
myset.add('timestamp') 
#myset memory location has been mutated to contain 'timestamp'
而我想

myset = set(somelist).add('timestamp') #mutation or not, it's functional for all I care

您可以使用
union
方法:

myset=set(somelist).union(['timestamp'])

您可以使用
联合
方法:

myset=set(somelist).union(['timestamp'])