• Sets are used to store multiple items in a single variable.
  • Set is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Tuple, and Dictionary, all with different qualities and usage.
  • A set is a collection which is unordered, unchangeable*, and unindexed.
thisset = {"apple", "banana", "cherry", "apple"}  
print(thisset)
thisset = {"apple", "banana", "cherry"}  
  
print("banana" in thisset)
# true
Add item in set
thisset = {"apple","banana"}
thisset.add("orange")
print(thisset)
Update item in set
thisset = {"apple", "banana", "cherry"}  
tropical = {"pineapple", "mango", "papaya"}  
  
thisset.update(tropical)  
  
print(thisset)
# {'apple', 'mango', 'cherry', 'pineapple', 'banana', 'papaya'}
Remove item in set
thisset = {"apple", "banana", "cherry"}  
thisset.remove("banana")  
print(thisset)
Methods