📖 generic · 12th TN - English Medium · COMPUTER SCIENCE · Page 138question

LISTS, TUPLES, SETS AND DICTIONARY · Part 16

Chapter 3: 4 · COMPUTER SCIENCE

{ , , , . , '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

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →