标签:lin 原来 pre 可重复 可变 section 交集 nio jason
s = {1,2,1,'a'} # s = set({1,2,'a'})
print(s) # {1,2,'a'}
1:len 长度
s = {1,2,3}
print(len(s)) # 3
2:成员运算 in 和 not in
s = {1,3,5,'a'}
print('a' in s) # True
print('a' not in s) #False
3:| 并集(union)
pythoners = {'jason','nick','egon','jin'}
linuxers = {'kevin','nick','egon'}
print(pythoners | linuxers)
# {'nick', 'jason', 'jin', 'kevin', 'egon'}
4:& 交集(intersection)
pythoners = {'jason','nick','egon','jin'}
linuxers = {'kevin','nick','egon'}
print(pythoners & linuxers)
# {'egon', 'nick'}
5:- 差集(difference)
pythoners = {'jason','nick','egon','jin'}
linuxers = {'kevin','nick','egon'}
print(pythoners - linuxers)
# {'jin', 'jason'}
6:^ 对称差集(symmetric_difference)
pythoners = {'jason','nick','egon','jin'}
linuxers = {'kevin','nick','egon'}
print(pythoners ^ linuxers)
# {'jason', 'kevin', 'jin'}
7: ==
pythoners = {'jason','nick','egon'}
linuxers = {'jason','nick','egon'}
print(pythoners == linuxers)
# False
8:父集 >,>=,(issuperset)
pythoners = {'jason','nick','egon','jin'}
linuxers = {'nick','egon'}
print(pythoners > linuxers) # True
print(pythoners >= linuxers) # True
9:子集 <,<=,(issubset)
pythoners = {'jason','nick','egon','jin'}
linuxers = {'nick','egon'}
print(linuxers < pythoners) # True
print(linuxers <= pythoners) #True
标签:lin 原来 pre 可重复 可变 section 交集 nio jason
原文地址:https://www.cnblogs.com/jincoco/p/11135415.html