| Collection (s). Method name |
Equivalent symbol |
Method description |
| S.issubset (t) |
S <= t |
Subset testing (allows for a subset of non-strict meanings): All elements in S are members of T |
|
S < T |
Subset testing (STRICTLY): s! = T and all elements in s are members of T |
| S.issuperset (t) |
S >= t |
Hyper-set test (allows for non-strict superset): All elements in T are members of S |
|
s > t |
Hyper-Set testing (STRICTLY): s! = T and all elements in T are members of S |
| S.union (t) |
s | T |
Merge operation: Elements in S "or" t |
| S.intersection (t) |
S & T |
Intersection operations: Elements in S "and" t |
| S.difference |
S-t |
Differential operation: An element that exists in s that does not exist in T |
| S.symmetric_difference (t) |
s ^ t |
Symmetric differential operation: elements in S "or" T, but not elements common to s and T |
| S.copy () |
|
Returns a copy of S (Shallow copy) |
| The following methods apply only to mutable collections |
|
|
| S.update |
S |= t |
Add an element from T to S |
| S.intersection_update (t) |
S &= t |
Intersection modification operation: s includes only members of S and T |
| S.difference_update (t) |
S-= t |
Difference modification operation: s includes members that belong only to s but are not part of T |
| S.symmetric_difference_update (t) |
S ^= t |
Symmetric differential modification operation: s includes only members belonging to s or only t |
| S.add (obj) |
|
Add an action: adding obj to S |
| S.remove (obj) |
|
Delete operation: Removes obj from S and throws an exception if obj does not exist in S |
| S.discard (obj) |
|
Discard operation: Remove obj from S, and if obj is not present in S, it's okay ^_^ |
| S.pop () |
|
Eject action: Remove and return any element in S |
| S.clear () |
|
Clear action: Clears all elements in s |
Python collection type built-in method summary