[4-1] Notes Python language foundation - a collection set

set

  Only store immutable objects

  Objects are unordered

  Can not be duplicated elements

Create Collection

s = {12, 32, 5436, 2, 44}
s2 = set({1, 2, 346, 7, 8})

in 和 not in

len (s1)

Adding elements

  s1.add() 

  s1.update(s2)

delete

  s1.pop () removes an element of random

  s1.remove (12) to delete the specified element

  s1.clear () empty set

copy () shallow copy

Collection operation

  & Intersection

  | Union

  - Set difference result = s1 - s2

  ^ Or will set

  <= Child Collection

  <Mako Collection

  

  

  

  

 

Guess you like

Origin www.cnblogs.com/ZZBD/p/12616565.html