1.

If a={5,6,7}, what happens when a.add(5) is executed?(a) a={5,5,6,7}(b) a={5,6,7}(c) Error as there is no add function for set data type(d) Error as 5 already exists in the setI had been asked this question in an online interview.My question is taken from Sets topic in division Tuples and Sets of Python

Answer»

Correct option is (b) a={5,6,7}

For explanation: There EXISTS add method for set data TYPE. However 5 isn’t added again as set CONSISTS of only non-duplicate elements and 5 already exists in the set. Execute in python SHELL to verify.



Discussion

No Comment Found

Related InterviewSolutions