There are many Python set functions. The following lists some frequently used functions:
For example, S = set ([1, 2, 3])
Some functions can be viewed through Dir (s) and help (s.
S. Update (t) uses the element in t to modify s, that is, s now contains s or t members.
Members in S. intersection_update (t) s are elements of S and T.
Members in S. difference_update (t) s belong to s but are not included in T.
Members in S. symmetric_difference_update (t) s are updated to elements that are included in S or T but not shared by S and T.
S. Add (OBJ) add object OBJ in set S
S. Remove (OBJ): delete object OBJ from set S. If obj is not an element (OBJ not in S) in set S, A keyerror error is thrown.
S. Discard (OBJ) If obj is an element in set S, delete the object OBJ from set S;
S. Pop () deletes any object in set S and returns it
S. Clear () deletes all elements in set S.
Len (s) set base: number of elements in set S
Set ([OBJ]) variable set factory function; OBJ must support iteration. The element in OBJ creates a set. Otherwise, an empty set is created.
Frozenset ([OBJ]) is an unchangeable set factory function. The execution method is the same as the Set () method, but it returns an unchangeable set.
OBJ in S member test: Is OBJ an element in S?
OBJ not in s non-member test: Isn't OBJ an element in S?
S = T equivalent test: test whether s and t have the same element?
S! = T Non-equivalent test: opposite to =
S <t (strictly speaking) subset test; s! = T and all elements in S are members of T
S. issubset (t) S <= T subset test (subset not strictly allowed): All elements in S are members of T.
S> T (strictly speaking) superset test: s! = T and all the elements in T are members of S.
S. issuperset (t) S> = T superset test (superset not strictly allowed): All elements in T are members of S.
S. Union (t) S | T merge operation: Elements in S or t
S. InterSec-tion (t) S & T intersection operation: Elements in S and T
S. difference (t) S-t differential operation: Elements in S, not elements in T
S. symmetric_difference (t) s ^ t Symmetric Difference Operation: an element in S or t, but not a common element of S and T
S. Copy () copy operation: returns the (Shortest copy) Copy of S.