In Java or C we have
<condition> ? X : Y
X if <condition> else Y
<condition> and X or Y
While I understand that it's equivalent to the aforementioned ternary operators
This is incorrect:
In : True and 0 or 1 Out: 1 In : True and 2 or 1 Out: 2
Why the first expression returns
Y), while the condition is
True and the "expected" answer is
According to the docs:
The expression x and y first evaluates x; if x is false, its value is returned; otherwise, y is evaluated and the resulting value is returned.
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.
True and 0 or 1 evaluates the first argument of the
and operator, which is
True. Then it returns the second argument, which is
True and 0 returns false value, the
or operator returns the second argument (i.e.