A collection of
1. Definitions
{} The plurality of elements spaced apart by commas, element satisfies the following conditions:
a, elements within the set of immutable type
print (set ([1,1,1,1,1,1, [11,222]]) # error
b, the unordered collection of elements
C, within the set of elements can not be repeated, a repeat element count only
2, built-in method
Relational operators ============== =============
a, on the intersection: two sets of the same elements
res = friends1 & friends2
b, and take the set / Collection: All the elements of the set of two
res = friends1 | friends2
C, taking the difference set: a set of common elements in the extraction, the remaining difference is set
friends1 的:res = friends1 - friends2
friends2 的:res = friends2 - friends1
d, symmetric difference: a unique set of two elements, i.e., elements common to remove
res = friends1 ^ friends2
e, parent subset
1, S1: {1,2,3}
s2: {1,2,4} # inclusion relationship does not exist
print(s1>s2) #False
2, only when the set of s1 s2 subordinate, s1 and s2 set to become a father
When s1 = s2, the mutual parent subset
================ deduplication ===============
Only for immutable type, can not guarantee that the original order
Other built-in method ####
Two-character encoding
Details, refer to: https: //zhuanlan.zhihu.com/p/108805502
##Analysis process
unicode(内存中统一使用unicode):
结论:
其他内置方法
s={1,2,3}
需要掌握的内置方法1:discard
s.discard(4) # 删除元素不存在do nothing
print(s)
s.remove(4) # 删除元素不存在则报错
需要掌握的内置方法2:update
s.update({1,3,5})
print(s)
需要掌握的内置方法3:pop
res=s.pop()
print(res)
需要掌握的内置方法4:add
s.add(4)
print(s)