Sets

Sets are unordered collection and unindexed (cannot be accessed directly) stored in curly brackets "{ }"

The following code assigns a sample set to a variable, which can then be used to manipulate.

example_set = {1, 'a', True}

Access

for x in example_set:
     item = x

As part of access, you can check if a certain item is in the set, as shown below.

Check if in list -> Returns True or False

check = 1 in example_set

Add

Add Item

example_set.add ('b')

Add two sets ~ update() can be used to any iterable objects

example_set2 = {2, 'c', False}
example_set.update (example_set2)

Remove

example_set.remove ('a')

If 'a' does not exist, then discard() does not raise an error

example_set.discard ('a')