学习笔记(27):Python入门教程-集合的关系运算

立即学习:https://edu.csdn.net/course/play/24459/296269?utm_source=blogtoedu

集合的关系运算

s_1024 = {"佩奇","老男孩","海峰","马jj","老村长","黑姑娘","Alex"}
s_pornhub = {"Alex","Egon","Rain","马jj","Nick","jack"}
print(s_1024 & s_pornhub) #交集 and
print(s_1024 | s_pornhub) #并集 or
print(s_1024 - s_pornhub) #差集,only in 1024
print(s_pornhub - s_1024) #only in s_pornhub
print(s_1024 ^ s_pornhub) #对称差集,两个里面相同踢出去

s_1024.isdisjoint(s_pornhub)) #判断两个几个是否不相交,返回True或False

s_1024.issubset(s_pornhub)) #判断是否为子集,返回布尔值

s_1024.issuperset(s_pornhub)) #判断是否父集,返回布尔值

s_1024.difference(s_pornhub)) #差集,同s_1024 - s_pornhub

s_1024.intersection(s_pornhub)) #取交集

s_1024.symmetric_difference(s_pornhub)) #取对称差集

s_1024.union(s_pornhub)) #取合集

s_1024.difference_update(s_pornhub) #取完差集后再赋值给s_1024

 

 

你可能感兴趣的:(研发管理,python,编程语言,Python,小猿圈,Python入门教程)