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.
CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad