Vidyalelo
Python · Q83

Functions in Python

Programming · Python · question 83

Q83

What will be the output of the following Python code? def foo(i, x=[]): x.append(x.append(i)) return x for i in range(3): y = foo(i) print(y)

A.
[[[0]], [[[0]], [1]], [[[0]], [[[0]], [1]], [2]]]
B.
[[0], [[0], 1], [[0], [[0], 1], 2]]
C.
[0, None, 1, None, 2, None]
Answer
D.
[[[1]], [[[0]], [1]], [[[0]], [[[0]], [1]], [2]]]

Answer: Option C

Solution

Answer: Option C
No explanation is given for this question Let's Discuss on Board