A set is a collection which is unordered and unindexed. In Python sets are written with curly brackets.
1. CREATE A SET IN PYTHON
thisset = {"apple", "banana", "cherry"} print(thisset)
OUTPUT:

2. ACCESS ITEMS OF SET IN PYTHON
You cannot access items in a set by referring to an index, since sets are unordered the items has no index.
2.1 ITERATE (loop) THROUGH A SET IN PYTHON
You can loop through the set items using for loop, or ask if a specified value is present in a set, by using the in keyword.
thisset = {"apple", "banana", "cherry"} for x in thisset: print(x)
OUTPUT:

2.2 CHECK IF ITEM EXISTS IN SET IN PYTHON
To check if ‘banana’ is present in the set:
thisset = {"apple", "banana", "cherry"} print("banana" in thisset)
OUTPUT:

3. CHANGE ITEMS IN PYTHON
Once a set is created, you cannot change its items, but you can add new items.
4. ADD ITEMS IN SET IN PYTHON
To add one item to a set use the add() method.
4.1 add() METHOD OF SET IN PYTHON
To add more than one item to a set use the update() method.
thisset = {"apple", "banana", "cherry"} thisset.add("orange") print(thisset)
OUTPUT:

4.2 update() METHOD OF SET IN PYTHON
Add multiple items to the set using the update() method.
thisset = {"apple", "banana", "cherry"} thisset.update(["orange", "mango", "grapes"]) print(thisset)
OUTPUT:

5. GET THE LENGTH OF A SET IN PYTHON
To determine how many items a set has, use the len() method.
thisset = {"apple", "banana", "cherry"} print(len(thisset))
OUTPUT:

6. REMOVE ITEM FROM SET IN PYTHON
To remove an item in a set, use the remove(), or the discard() method.
thisset = {"apple", "banana", "cherry"} thisset.remove("banana") print(thisset)
thisset.discard("apple")
print(thisset)
OUTPUT:
