A set is a collection which is unordered, unchangeable*, unindexed ,do not allow duplicate values. Set items are unchangeable, but you can remove items and add new items.
thisset = {1,"apple", "banana", "cherry",232,True,0,"p",2}
print(thisset) #output -> {0, 1, 2, 'p', 'cherry', 232, 'apple', 'banana'}
print(type(thisset)) #output -> <class 'set'>
print(len(thisset)) #output -> 8
thisset = set(("apple", "banana", "cherry")) # note the double round-brackets
print(thisset)
thisset = {"apple", "banana", "cherry"}
for x in thisset:
print(x)
banana
apple
cherry
thisset = {"apple", "banana", "cherry"}
print("banana" in thisset) #output -> True
thisset = {"apple", "banana", "cherry"}
thisset.add("orange")
print(thisset) #output -> {'orange', 'banana', 'apple', 'cherry'}
thisset = {"apple", "banana", "cherry"}
tropical = {"pineapple", "mango", "papaya"}
mylist = ["kiwi", "orange",67]
thisset.update(tropical)
thisset.update(mylist)
print(thisset) #output -> {67, 'orange', 'cherry', 'pineapple', 'mango', 'apple', 'kiwi', 'banana', 'papaya'}
thisset = {"apple", "banana", "cherry"}
thisset.remove("banana")
print(thisset) #output -> {'apple', 'cherry'}
thisset = {"apple", "banana", "cherry"}
thisset.discard("banana")
print(thisset) #output -> {'apple', 'cherry'}
thisset = {"apple", "banana", "cherry"}
x = thisset.pop()
print(x) #output -> banana
print(thisset)#output -> {'apple', 'cherry'}
thisset = {"apple", "banana", "cherry"}
thisset.clear()
print(thisset) #output -> set()
thisset = {"apple", "banana", "cherry"}
del thisset
set1 = {"a", "b" , "c"}
set2 = {1, 2, 3,4}
set3 = set1.union(set2)
print(set3) #output -> {'a', 1, 2, 3, 'b', 4, 'c'}
set1 = {"a", "b" , "c"}
set2 = {1, 2, 3,9090}
set1.update(set2)
print(set1) #output -> {'a', 1, 2, 3, 'b', 9090, 'c'}
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
x.intersection_update(y)
print(x) #output -> {'apple'}
intersection() method will return a new set, that only contains the items that are present in both sets
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.intersection(y)
print(z) #output -> {'apple'}
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
x.symmetric_difference_update(y)
print(x) #output -> {'cherry', 'microsoft', 'banana', 'google'}
symmetric_difference() method will return a new set, that contains only the elements that are NOT present in both sets
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.symmetric_difference(y)
print(z) #output -> {'cherry', 'microsoft', 'banana', 'google'}
Python - Set Methods https://www.w3schools.com/python/python_sets_methods.asp