The set
in Python is used to store values like an array and ensure there are no duplicates. i.e. set is a list of unique items.
set_name = set()
set_name = set([value1, value2])
set_name.add(value3)
Note:
|
symbol), intersection (&
symbol), difference (-
symbol), and symmetric difference (^
symbol).in
' and 'not in
' can be used to check for the existence of values in a set.>>> integers = set([1, 2, 3, 4, 5])
>>> integers.add(6)
>>> integers
{1, 2, 3, 4, 5, 6}