What will be the output of the following Python function? [code]{x for x in 'abc'} {x*3 for x in 'abc'}[/code]

Man Ly

New member
What will be the output of the following Python function?
Code:
{x for x in 'abc'}
{x*3 for x in 'abc'}
A.
{abc}
aaa
bbb
ccc
B.
abc
abc abc abc
C.
{‘a’, ‘b’, ‘c’}
{‘aaa’, ‘bbb’, ‘ccc’}
D.
{‘a’, ‘b’, ‘c’}
abc
abc
abc
 
Answer: c
Explanation: The first function prints each element of the set separately, hence the output is: {‘a’, ‘b’, ‘c’}. The second function prints each element of the set thrice, contained in a new set. Hence the output of the second function is: {‘aaa’, ‘bbb’, ‘ccc’}. (Note that the order may not be the same)
 

Tìm kiếm

Back
Top