Report Bug

Qus

What will be the output of the following Python code?

def foo(i, x=[]):      x.append(i)      return x  for i in range(3):      print(foo(i))
Qusनिम्नलिखित Python कोड का आउटपुट क्या होगा?


A. [0] [1] [2]
B. [0] [0, 1] [0, 1, 2]
C. [1] [2] [3]
D. [1] [1, 2] [1, 2, 3]


Solution
B. [0] [0, 1] [0, 1, 2]



Explanation
When a list is a default value, the same list will be reused.
Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad