NIELIT O Level Exam

<p>What will be the output of the following Python code?</p><pre><span style="font-size: 14px;">def f1(a,b=[]):<br></span><span style="font-size: 14px;">&nbsp; &nbsp; b.append(a)<br></span><span style="font-size: 14px;">&nbsp; &nbsp; return b<br></span><span style="font-size: 14px;">print(f1(2,[3,4]))</span></pre><div><br></div>

What will be the output of the following Python code?

def f1(a,b=[]):
    b.append(a)
    return b
print(f1(2,[3,4]))


निम्नलिखित Python कोड का आउटपुट क्या होगा?

def f1(a,b=[]):
    b.append(a)
    return b
print(f1(2,[3,4]))

A. [3,2,4]

B. [2,3,4]

C. Error एरर

D. [3,4,2]




Correct Answer is :

D. [3,4,2]



Explanation
In the code shown above, the integer 2 is appended to the list [3,4]. Hence the output of the code is [3,4,2]. Both the variables a and b are local variables.
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