集合

#定义两个不同的值
python_1=['lcg','zjw','szw']
liunx =['lcg','szw','sb']
p_s=set(python_1)
p_l=set(liunx)
print(p_s,p_l)
#交集
print(p_s.intersection(p_l))#函数:intersection
print(p_s&p_l)
#并集
print(p_s.union(p_l))#函数:union
print(p_s|p_l)
#差集
print('差集',p_s-p_l)
print(p_s.difference(p_l))#函数difference
print('差集',p_l-p_s)
原文地址:https://www.cnblogs.com/huangjinshan/p/6231292.html