Create Set Using Constructor :
thisset = set(("apple", "banana", "cherry"))
print(thisset)
Output :
{'apple', 'banana', 'cherry'}
Loop Through Set :
thisset = {"apple", "banana", "cherry"}
for x in thisset:
print(x)
Output :
apple
banana
cherry
Check if Item Exists in Set :
thisset = {"apple", "banana", "cherry"}
print("banana" in thisset)
Output :
True
Add Item to Set :
thisset = {"apple", "banana", "cherry"}
thisset.add("orange")
print(thisset)
Output :
{'apple', 'banana', 'cherry', 'orange'}
Add Items from Another Set :
thisset = {"apple", "banana", "cherry"}
tropical = {"pineapple", "mango", "papaya"}
thisset.update(tropical)
print(thisset)
Output :
{'apple', 'banana', 'cherry', 'mango', 'papaya', 'pineapple'}