# Set auto-weight, but no value, only key
s = Set ([3, 5, 9, ten]) # Create a collection of values
t = Set ("Hello") # Creates a collection of unique characters
x = ' x '
A = T | the set of S # T and S
b = Intersection of T & S # T and S
c = T -S # differential set (items in T, but not in s)
D = t ^ s # symmetric difference set (items in t or S, but not both)
# Basic Operation:
T.add (' x ') # Add an item
S.update ([Ten, Panax Notoginseng]) # Add multiple items in S
# Use Remove () to delete an item:
T.remove (' H ')
Len (s)
# The length of the set
X in S
# Test if X is a member of S
X not in S
# Test if X is not a member of S
S.issubset (t)
S <= t
# Test if every element in S is in t
S.issuperset (t)
S >= t
# Test if every element in T is in S
S.union (t)
s | T
# Returns a new set containing each element in S and T
S.intersection (t)
S & T
# Returns a new set containing the common elements in S and T
S.difference (t)
S-t
# Returns a new set containing elements in s but not in t
S.symmetric_difference (t)
s ^ t
# Returns a new set containing elements that are not duplicates in S and T
S.copy ()
# Returns a shallow copy of set "s"
Python Collection Set