How do I add two sets?

后端 未结 3 827
南旧
南旧 2020-12-08 18:14
a = {\'a\', \'b\', \'c\'} 
b = {\'d\', \'e\', \'f\'}

I want to add above two set values. I need output like

c = {\'a\', \'b\', \'c\',         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 18:58

    All you have to do to combine them is

    c = a | b
    

    Sets are unordered sequences of unique values. a | b or a.union(b) is the union of the two sets (a new set with all values found in either set). This is a class of operation called a "set operation", which Python sets provide convenient tools for.

提交回复
热议问题