Set Data Structure: =================== () ==> allows duplication [] ==> allows duplication {} ==> not allows the duplication 1) When we need to create the data structure which is not with any duplication then, we can use the set. 2) set can be defined with {} all the elements {} must be separate with comma. 3) set can possible to define homogeneous elements and with heterogeneous elements also. 4) Set is also the pre-defined data, so we have a pre-defined class named as "set". s1 = {} print(type(s1)) # dictionary # to create empty set, we can use "set()". s2 = set() print(type(s2)) s2 = {11,10,22,20,11,10,22,20} print(type(s2)) s3 = {'a',True,1.2,12-23j,23} print(type(s3)) Is set ordered data? -------------------- Not ordered. -> indexing is not possible. -> slicing also not possible. Is set mutable or immutable? ---------------------------- Mutable add(): ----- -> if you want to add only one element to the set at any random position, we can use "add()". Syntax: set-data.add(element) update(): --------- when we want to add more than one element to the set, we can use "update()" Syntax: set-data.update([e1, e2, e3,...]) s1 = {11,22,10,20,30,22,11,20,10,7,9} print(s1) # print(s1[0]) print(id(s1)) s1.add(55) print(s1) print(id(s1)) s1.update((100,200,300,400)) print(s1) s1.update(range(5,50,10)) print(s1) print(id(s1)) How to remove elements? ------------------------ pop(): ----- -> pop() can remove any element randomly from the set. Syntax: set-data.pop() remove(): --------- -> when we want to remove the specified element from the set we can use "remove()". Syntax: set-data.remove(element) Note: ---- if the specified element is not in the set, remove() can give "key error". discard(): --------- -> also remove the specific element from the set. Syntax: set-data-name.discard(element) s1 = {1,11,10,20,22,20,7,9} print(s1) s1.pop() print(s1) s1.add(100) print(s1) s1.pop() print(s1) s1.remove(11) print(s1) # s1.remove(101) s1.discard(9) print(s1) s1.discard(101) Note: ----- No math operations like concatenation and repetition allowed on sets.