The collection uses curly braces to separate the elements with commas. The same element does not appear in the output of the collection. There are set, intersection, and difference sets, and the following are some simple expressions:
def main (): list1=[1,1,2,2,3,3] print (list1) set1={1,1,2,2,3,3} print (Set1) Set1.add (4) Set1.add (5) print (Set1) set2={1,3,5,7,9} print (Set2) Set3=set1 & Set2 #set3 = Set1.intersection (Set2) print (set3) set3=set1 | Set2 #st3 =set1.union (Set2) print (SET3) Set3=set1-set2 #set3 =set1.difference (Set2) print (set3) Set3 = set2.difference (Set1) print ( Set3) set3=set1 ^ Set2 #set3 =set1.symmetric_difference (Set2) print (Set3) for Val in Set2: Print (val) print (Set2.pop ()) if 3 in Set2: set2.remove (3) print (Set2) print (set2<= Set1) #print (Set2.issubset (set1)) print (Set1>=set2) #print (Set1.issuperset (Set2)) If __name__ = = ' __main__ ': Main () results: [1, 1, 2, 2, 3, 3]{1, 2, 3}{1, 2, 3, 4, 5}{1, 3, 5, 7, 9}{1, 3, 5}{1, 2, 3, 4, 5, 7, 9}{2, 4}{ 9, 7}{2, 4, 7, 9}135791{5, 7, 9}falsefalse
Python basic knowledge Note-collection