106k views
1 vote
What do the following lines output, and why?

(1 < 2 < 3);
(3 > 2 > 1);

1 Answer

1 vote

Final answer:

The expressions (1 < 2 < 3) and (3 > 2 > 1) output True and False respectively.

Step-by-step explanation:

The expressions (1 < 2 < 3) and (3 > 2 > 1) output True and False respectively.



In the first expression, both 1 < 2 and 2 < 3 are True, so the result is True.



However, in the second expression, 3 > 2 is True, but 2 > 1 is False. In Python, the comparison operator is evaluated from left to right, so 3 > 2 > 1 is equivalent to (3 > 2) and (2 > 1). Since 2 is not greater than 1, the result is False.

User Sourav Dey
by
8.7k points

No related questions found