Report Bug

Qus

What will be the output of the following Python code?

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

निम्नलिखित 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]


Solution
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