https://www.zhihu.com/column/c_1216656665569013760

 

 

集合的运算

set2 = {1, 3, 4, 5, 6, 7, 8}
set3 = {4, 5, 6, 7, 8, 9, 0, '1', 'a'}

# 交集
# print(set2 & set3)
# print(set2.intersection(set3))

# 加赋值
# set2 |= set3

# 并集
# print(set2 | set3)
# print(set2.union(set3))

# 差集
# print(set2 - set3)
# print(set2.difference(set3))

# 差集加赋值
# set2 -= set3
# print(set2)

# 对称差
# print(set2 ^ set3)
# print(set2.symmetric_difference(set3))
# print((set2 | set3) - (set2 & set3))

 

posted on 2023-11-25 11:04  北极熊的菜  阅读(3)  评论(0编辑  收藏  举报