Practice mode Python

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.