1 #!/usr/bin/env python 2 # 世上最美的,莫过于从泪水中挣脱出来的那个微笑 3 # Author: Msl23 4 5 # 集合 6 t = set([2,3,1,7,8,99]) 7 s = set([2,3,5,7,88,8]) 8 print(t,‘\n‘,s) 9 10 #并集:| = union 11 c = t | s 12 print(c) 13 14 #交集 & = intersection 15 d = t & s 16 print(d) 17 18 #差集: - = difference 19 20 e = t - s 21 print(e) 22 f = s - t 23 print(f) 24 25 #对称差集 ^ = symmetric_difference 26 g = t ^ s 27 print(g)
时间: 2024-10-31 20:14:55