Python MCQ and Answers – Part 15
This collection of Python Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer.
1. Only problems defined recursively can be solved using recursion
A True
B False
2. Which of the following statements is wrong about recursion?
A Recursive function can be replaced by a non-recursive function
B Recursive functions are faster than non-recursive functions
C Recursive functions generally take more memory than non-recursive functions
D Recursion makes programs easier to understand
3. What is the output of the following code?
list1 = [1, 2, 3, 4] list1.extend([5, 6]) print(list1)
A [1, 2, 3, 4]
B [1, 2, 3, 4, 5, 6]
C [1, 2, 3, 4, 5]
D [5, 6, 1, 2, 3, 4]
4. What is the output of the following code?
list1 = [1, 2, 3, 4] list1.pop(1) print(list1)
A [2, 3, 4]
B [1, 2, 3]
C [4, 3, 2]
D [1, 3, 4]
5. What is the output of the following code?
list1 = [1, 2, 3, 4] list1.pop() print(list1)
A [2, 3, 4]
B [1, 2, 3]
C [4, 3, 2]
D [1, 3, 4]
6. What is the output of the following code?
>>>"Welcome to StackHowTo".split()
A “Welcome”, “to”, “StackHowTo”
B {“Welcome”, “to”, “StackHowTo”}
C (“Welcome”, “to”, “StackHowTo”)
D [“Welcome”, “to”, “StackHowTo”]
7. What is the output of the following code?
>>>list("w#x#y#z".split('#'))
A [‘wxyz’]
B [‘w x y z’]
C [‘w’, ‘x’, ‘y’, ‘z’]
D [‘w#x#y#z’]
8. Complete the following code to calculate the factorial of a number.
def fact(n): if n == 0: return 1 else: return ........
A fact(n)*fact(n-1)
B n*fact(n-1)
C n*(n-1)
D (n-1)*(n-2)
9. What is the purpose of setattr()?
A To set an attribute
B To access the object attribute
C To check if an attribute exists or not
D Delete an attribute
10. Which methods start and end with two underscores “__”?
A Special methods
B Integrated methods
C Additional methods
D User defined methods
11. Which of these fields is a private data field?
def MyClass: def __init__(self): __x = 1 self.__y = 1 self.__z__ = 1 __t__= 1
A __x
B __y
C __z__
D __t__