Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python
Program 1
#Methods of Set Collection
# myset={10,"Indore",89.99,True}
# myset.add("Mumbai")
# print(myset)
# myset.clear()
# print(myset)
# myset1=myset
# print(myset)
# print(myset1)
# myset.add("Mumbai")
# myset.add("Mumbai")
# print(len(myset))
# print("Before Remove: ",myset)
# myset.remove("Indore")
# print("Before Remove: ",myset)
# print("Before Pop:",myset)
# myset.pop()
# print("After Pop:",myset)
# Return a set that contains all data elements from both sets, duplicates are excluded:
# myset1 = {"first", "second", "third"}
# myset2 = {"four", "five", "first"}
# myset3 = myset1.union(myset2)
# print(myset3)
# Return a set that contains the items that only exist in set myset1, and not in set myset2:
# myset1 = {"first", "second", "third"}
# myset2 = {"four", "five", "first","third"}
# myset3 = myset1.difference(myset2)
# print(myset3)
#Return a set that contains the items that exist in both set myset1, and set myset2:
# myset1 = {"first", "second", "third","four"}
# myset2 = {"four", "five", "first"}
# myset3 = myset1.intersection(myset2)
# print(myset3)
# myset1 = {"first", "second", "third","four","five"}
# print("Before discard: ",myset1)
# myset1.discard("second")
# print("After discard: ",myset1)
# myset1 = {"first", "second", "third"}
# myset2 = {"four", "five", "first"}
# myset1.update(myset2)
# print(myset1)