{ , , , . , 'A'} >>> S2={ , , ,'A', . } >>> print(S2) { , , 'A', . } Example In the above examples, the set S1 is created with different types of elements without duplicate values.
Whereas in the set S2 is created with duplicate values, but python accepts only one element among the duplications. Which means python removed the duplicate value, because a set in python cannot have duplicate elements. When you print the elements from a set, python shows the values in different order. Note .
. Creating Set using List or Tuple A list or Tuple can be converted as set by using set() function. This is very simple procedure. First you have to create a list or Tuple then, substitute its variable within set() function as argument.
MyList=[ , , , , ] MySet=set(MyList) print(MySet) Output: { , , , , } Example 12th Computer Chapter - - . . Set Operations As you learnt in mathematics, the python is also supports the set operations such as Union, Intersection, difference and Symmetric difference. (i) Union: It includes all elements from two or more sets