What is the output of the following Python code snippet?
from collections import namedtuple
P = namedtuple('Point', 'x y')
print(P(1, 2))
-
A
Point(x=1, y=2)
Correct answer
-
B
(1, 2)
-
C
Point(1, 2)
-
D
Error
Correct answer
A. Point(x=1, y=2)
5 views
Explanation
A namedtuple prints its fields by name.
Doubts & discussion
Not sure why the answer is A? Ask here and get an explanation.
Ask a doubt about this MCQ