What will be the output of the following Python program? z=set(‘abc’) z.add(‘san’) z.update(set([‘p’, ‘q’])) z

Questions & AnswersCategory: Programming LanguageWhat will be the output of the following Python program? z=set(‘abc’) z.add(‘san’) z.update(set([‘p’, ‘q’])) z
Geek Boy Staff asked 2 years ago

What will be the output of the following Python program?

z=set('abc')
z.add('san')
z.update(set(['p', 'q']))
z

a. {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}
b. {‘abc’, ‘p’, ‘q’, ‘san’}
c. {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
d. {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san}

1 Answers
Geek Boy Staff answered 2 years ago

c. {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
Explanation: The code shown first adds the element ‘san’ to the set z. The set z is then updated and two more elements, namely, ‘p’ and ‘q’ are added to it. Hence the output is: {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}