Welcome to our Python conditional statements MCQ quiz! Here, we have listed the best collection of important questions based on Python conditional statements in quiz format, with answers and explanations.
This Multiple-Choice Question (MCQ) is designed to test your knowledge of conditional statements, such as if statement, if-else, etc. in Python from basic syntax to advanced concepts. Whether you’re preparing for a job interview, a coding competition, or just want to sharpen your coding skills, these multiple-choice questions will challenge your understanding.
Each question has four options and you have to choose the correct one. There is no time limit to answer the questions. However, you can set a time limit for yourself to simulate exam conditions. You can also bookmark this Python conditional statements MCQ to revise before exams!
Are you ready to test your knowledge on conditional statements in Python? Let’s see if you can score 30/30—start now with question 1! 👇
x = 10
y = 20
if x > y:
print("X is greater")
else:
print("Y is greater")x = 0
if x:
print("True")
else:
print("False")x = 10
y = 20
if x > 5:
if y < 15:
print("Case 1")
else:
print("Case 2")
else:
print("Case 3")x = 5
if x == 5 or x / 0:
print("No Error")x = False
y = True
if x == y:
print("Equal")
elif x:
print("X is True")
else:
print("X is False")x = 5
if x > 1:
print("Hello")
if x > 3:
print("Hello")
elif x > 2:
print("Hello")
else:
print("Hello")x = 0
if x:
print("A")
elif not x:
if x is not None:
print("B")
else:
print("C")
else:
print("D")x = 10
if x > 5:
pass
elif x > 7:
print("A")
else:
print("B")
print("C")x = 5
y = 10
if x < y: print("A"); print("B")
else: print("C"); print("D")if len(name) > 5:
size = "Long"
else:
size = "Short"a = False
b = True
if a and b or not a and b:
print("A")
elif a or not b:
print("B")
else:
print("C")x = 0
if x:
print("A")
if not x:
print("B")
if x == False:
print("C")
if x is False:
print("D")- In Python, 0 is considered as False in a boolean context. Therefore, first condition is False, and “A” is not printed.
- The condition not x checks if x is False. Since x = 0 is False, this condition is True, and “B” is printed.
- The condition x == False performs a value comparison. Since 0 == False is True, this condition is True, and “C” is printed.
- The last condition x is False checks for identity, not value. Since 0 is an integer, while False is a boolean type, 0 is False is False. So, “D” is not displayed.
values = [1, 2, 3]
if values:
print("A")
if len(values) > 0:
print("B")
if values is not None:
print("C")- In Python, non-empty lists are considered as True in a boolean context. Since values = [1, 2, 3] is non-empty, this condition is True and “A” is displayed.
- When Python executes if len(values) > 0:, the len(values) returns 3, which is greater than 0. So, this condition is also True, and “B” is also displayed.
- The condition values is not None: in if statement checks if the variable exists and is not None. Since values = [1, 2, 3] is a valid list, and it is not None, so this condition is True, and “C” is printed.
- In the first option, there is a walrus operator := (introduced in Python 3.8) which allows assignment within a conditional. So, this is valid.
- In the second option, x = 10 is an assignment, not a comparison. In conditional statements, you must use == for equality checking. This is not valid, hence it is the correct answer.
- In the third option, there is also a valid conditional statement that checks if x is greater than 10 and y is less than 20. Option d also contains the conditional statements. So, it is also valid.
values = [0, False, '', None, [], {}]
count = 0
for item in values:
if not item:
count += 1
print(count)x = []
- In Python, an empty list represents False, so if not x: is True when x = []. This condition evaluates to True.
- In the second option, the condition x == False performs a value comparison, and bool([ ]) is False. So, x == False is True.
- In the third option, the condition len(x) == 0 checks the length of the list, which is 0 for an empty list. So, this is also True.
- In the last option, the condition x is None checks for identity, not just value. Since an empty list [ ] is not the same object as None, so this evaluates to False. Hence, the final answer is d.
x = 5
y = 10
if x > 2 and y < 20 or x + y == 15:
print("A")
else:
print("B")x = 5
if 1 < x < 10:
print("Hello")
if (1 < x) < 10:
print("Hi")if (x := 0) or (y := 1):
print(x, y)
else:
print(y, x)def test():
print("Called")
return False
if True or test():
print("One")
if False and test():
print("Two")- In Python, True or test() uses short-circuit evaluation. The behavior of the OR operator is such that if the first condition is True, the second part is never evaluated. Since True is the first condition, the function test() will not be called. Therefore, “Called” is not displayed. When Python interpreter will execute if block, “One” will display.
- The condition False and test() will also use short-circuit evaluation. In Python, the behavior of the AND operator is such that if the first condition is False, the second part is never evaluated. Since False is the first condition, the function test() will not be called. So, “Called” is not displayed. Thus, if block does not execute, and “B” is not displayed.
(:=) in conditionals?


