1、add
# v = {1,2}
# v.add('Lishaoqi')
# v.add('Lishaoqi')
# print(v)
2、discard
# v = {1,2,'李邵奇'}
# v.discard('李邵奇')
# print(v)
3、update
# 2.3 批量添加
# v = {1,2,'李邵奇'}
# v.update({11,22,33})
# print(v)
4、intersection
交集,并集,差集,一般用来面试场景
# v = {1,2,'李邵奇'}
# result = v.intersection({1,'李邵奇','小黑'})
# print(result)
5、union
# v = {1,2,'李邵奇'}
# result = v.union({1,'李邵奇','小黑'})
# print(result)
6、difference
# v = {1,2,'李邵奇'}
# result = v.difference({1,'李邵奇','小黑'}) # v中有且{1,'李邵奇','小黑'}没有
# print(result)
# v1 = {1,'李邵奇','小黑'}
# result1 = v1.difference({1,2,'李邵奇'})
# print(result1)
7、symmetric_difference
# v = {1,2,'李邵奇'}
# result = v.symmetric_difference({1,'李邵奇','小黑'})
# print(result)
标签:set,20,独有,add,result,print,李邵奇,difference,小黑
From: https://www.cnblogs.com/jhchena/p/18432251