Python MCQ and Answers – Part 18
This collection of Python Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer.
1. What is the output of the following code?
def fun(): return count + 1 count = 0 print(fun())
A 0
B 1
C Error
D None
2. Which of the following represents the XOR operator?
A &
B |
C ^
D !
3. What happens if the base condition is not defined in a recursive program?
A The program goes into an infinite loop
B The program is executed once
C The program runs n times where n is the argument given to the function.
D An exception is thrown
4. Which of the following statements is not true about recursion?
A Make the code clean
B A complex task can be divided into subproblems
C Recursive calls use less memory
D All the answers are true
5. Which of the following statements is true?
A You cannot create custom exceptions in Python.
B You can create a user-defined exception by inheriting from the Exception class.
C You can create a user-defined exception by inheriting from the Error class.
D None of the above
6. What is the output of the following code?
def fun(x): x = ['alex', 'bob'] return id(x) names = ['bob', 'alex'] print(id(names) == fun(names))
A True
B False
C Error
D None
7. What is the output of the following code?
len(["str",1, 2, 3])
A 3
B 4
C 5
D Error
8. What is the output of the following code?
>>> d1 = {"alex":23, "jean":25} >>> d2 = {"alex":22, "jean":25} >>> d1 > d2
A False
B True
C None
D Error
9. What is the output of the following code?
>>> bin(10-2) + bin(12^4)
A 0b10000b10
B 0b10001000
C 0b10000b1000
D 0b10000
10. Suppose that dic = {“alex”: 20, “jean”: 25}
. To get the number of entries in the dictionary, which instruction do we use?
A dic.size()
B size(dic)
C dic.len()
D len(dic)