Python Arguments MCQs
This section focuses on the "Arguments" in Python. These Multiple Choice Questions (mcq) should be practiced to improve the Python skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. In Python, how are arguments passed?
A. pass by value
B. pass by reference
C. It gives options to user to choose
D. Both A and B
View Answer
Ans : B
Explanation: All parameters (arguments) in the Python language are passed by reference. It means if you change what a parameter refers to within a function, the change also reflects back in the calling function
2. Which of the following is incorrect way of using an argument while defining a function in Python, where var1 and var2 are two arguments?
A. def fn(var1, var2)
B. def fn(var1, var2=5)
C. def fn(*var1, var2)
D. def fn(var1,*var2)
View Answer
Ans : C
Explanation: def fn(*var1, var2) is incorrect way of using an argument while defining a function in Python.
3. Which of the following is not a type of argument in Python?
A. Keyword
B. Variable argument count
C. Positional
D. None of these
View Answer
Ans : D
Explanation: All of the above are the type of argument in Python.
4. Which of the following is the property of variable argument count?
A. More than one argument can be used while calling the function.
B. It should be always last while declaring the arguments.
C. Both A and B
D. None of these
View Answer
Ans : C
Explanation: More than one argument can be used while calling the function and It should be always last while declaring the arguments are the following is the property of variable argument count.
5. Which of the following would result in an error?
A. def function1(var1=2, var2):
var3=var1+var2
return var3
function1(3)
B. def function1(var1, var2):
var3=var1+var2
return var3
function1(var1=2,var2=3)
C. def function1(var1, var2):
var3=var1+var2
return var3
function1(var2=2,var1=3)
D. def function1(var1, var2=5):
var3=var1+var2
return var3
function1(2,3)
View Answer
Ans : A
Explanation: Option A would result in an error because var1=2 can not be defined before var2.
6. What will be the output of the following Python code?
def function1(var1=5, var2=7):
var2=9
var1=3
print (var1, " ", var2)
function1(10,12)
A. 5 7
B. 3 9
C. 10 12
D. Error
View Answer
Ans : B
Explanation: 3 9 will be the output of the following Python code.
7. What will be the output of the following Python code?
def function1(var1,var2=5):
var1=2
var3=var1*var2
return var3
var1=3
print(function1(var1,var2))
A. 10
B. 15
C. Error as var2 is not defined while calling the function
D. Does not give any error as var2 is a default argument
View Answer
Ans : C
Explanation: There will be an error in the code and the error is : Error as var2 is not defined while calling the function.
8. . Which among the following are mutable objects in Python?
(i) List
(ii) Integer
(iii) String
(iv) Tuple
A. i only
B. i and ii only
C. iii and iv only
D. iv only
View Answer
Ans : A
Explanation: List are mutable objects in Python.
9. What will be the output of the following Python code?
def function1(var1):
var1=var1+10
print (var1)
var1=12
function1(var1)
print(var1)
A. 22
22
B. 12
12
C. 22
22
D. 12
22
View Answer
Ans : C
Explanation: 22
22 will be the output of the following Python code.
10. What will be the output of the following Python code?
def fn(var1):
var1.pop(1)
var1=[1,2,3]
fn(var1)
print(var1)
A. [1,2,3]
B. [1,3]
C. [2,3]
D. [1,2]
View Answer
Ans : B
Explanation: [1,3] will be the output of the following Python code.
Discussion