What will be the output of the following Python code snippet? [code]s=set([1, 2, 3]) s.union([4, 5]) s|([4, 5])[/code]

Nguyễn Trà

New member
What will be the output of the following Python code snippet?
Code:
s=set([1, 2, 3])
s.union([4, 5])
s|([4, 5])
A.
{1, 2, 3, 4, 5}
{1, 2, 3, 4, 5}
B.
Error
{1, 2, 3, 4, 5}
C.
{1, 2, 3, 4, 5}
Error
D.
Error
Error
 
Answer: c
Explanation: The first function in the code shown above returns the set {1, 2, 3, 4, 5}. This is because the method of the function union allows any iterable. However the second function results in an error because of unsupported data type, that is list and set.
 

Tìm kiếm

Back
Top