-1
k = 10 / 3
l = k <= 3 or True

The value for l in this code returns True. How is this possible? In the order of evaluation, comparisons are higher prioritised than the "or, not, and" operators.

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253
Vitalynx
  • 89
  • 5
  • I'm duping this to this question http://stackoverflow.com/questions/16069517/python-logical-evaluation-order-in-if-statement in which a great top answer exists to complement my short one. – Dimitris Fasarakis Hilliard Oct 08 '16 at 18:56

1 Answers1

0

They do have a higher priority, but, the or operator works by:

The expression x or y first evaluates x; if x is true, its value is returned; otherwise, y is evaluated and the resulting value is returned.

Since k is 3.3333333333333335, the expression k <= 3 is False, True is going to be evaluated (to itself) and returned making l == True.

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253