Basic Python MCQs (1 to 20) with Answers
1. What is the output of: print(2 * 3 ** 2)
A. 36
B. 18 (Correct Answer)
C. 12
D. 14
2. What will this code print?
x=5
if x > 3:
print("A")
else:
print("B")
A. B
B. A (Correct Answer)
C. None
D. Error
3. Which of the following is a valid variable name in Python?
A. _var (Correct Answer)
B. 2ndVar
C. my-var
D. class
4. What data type is the result of input() in Python 3?
A. int
B. float
C. str (Correct Answer)
D. bool
5. Which loop executes at least once even if the condition is false?
A. for loop
B. while loop
C. do-while (Correct Answer)
D. loop
6. How many times will this loop execute?
for i in range(1, 5):
print(i)
A. 4
B. 4 (Correct Answer)
C. 5
D. 3
7. What is the output of:
a = 10
b = 20
print(a < b and a != b)
A. False
B. True (Correct Answer)
C. None
D. Error
8. Which keyword is used to define a function in Python?
A. function
B. define
C. def (Correct Answer)
D. func
9. What is the output of:
count = 0
while count < 3:
print(count)
count += 1
A. 0 1 2
B. 0 1 2 (Correct Answer)
C. 1 2 3
D. Infinite loop
10. What is the default value of an uninitialized variable in Python?
A. 0
B. ""
C. Python does not allow uninitialized variables (Correct Answer)
D. None
11. Which of the following is mutable?
A. int
B. float
C. list (Correct Answer)
D. tuple
12. How do you write a single-line comment in Python?
A. /* comment */
B. # comment (Correct Answer)
C. -- comment
D. // comment
13. What is the output of print(bool(0))?
A. True
B. False (Correct Answer)
C. 0
D. Error
14. What will this pseudo code do?
x=5
if x % 2 == 0:
print("Even")
else:
print("Odd")
A. Print "Odd" (Correct Answer)
B. Print "Even"
C. Error
D. None
15. What is the correct way to check if a number is even in Python?
A. num / 2 == 0
B. num // 2 == 0
C. num % 2 == 0 (Correct Answer)
D. num ^ 2 == 0
16. What is the data type of: True?
A. int
B. string
C. float
D. bool (Correct Answer)
17. Which of these is not a keyword in Python?
A. return
B. variable (Correct Answer)
C. for
D. try
18. What does the break statement do?
A. Skips current iteration
B. Exits the loop (Correct Answer)
C. Pauses execution
D. Restarts the loop
19. Which function converts a string to an integer?
A. string()
B. int() (Correct Answer)
C. float()
D. toInt()
20. Which operator is used for exponentiation in Python?
A. ^
B. %
C. ** (Correct Answer)
D. //