What is the output of the following Python code? print(3 > 2 > 1, (3 > 2) > 1)
Correct answer B. True False
Explanation
Comparisons chain in Python: 3 > 2 > 1 means 3 > 2 and 2 > 1, which is True. With parentheses, (3 > 2) is evaluated first and gives True, which behaves as the integer 1, so the second test becomes 1 > 1, which is False. Chained comparisons are a Python feature that differs from languages such as C.
Answer checked How we write and check questions
Discussion