i have line of code in script has both these operators chained together. documentation reference boolean and has lower precedence comparison greater than. getting unexpected results here in code:
>>> def test(msg, value): ... print(msg) ... return value >>> test("first", 10) , test("second", 15) > test("third", 5) first second third true i expecting second or third test happen before fist one, since > operator has higher precedence. doing wrong here?
https://docs.python.org/3/reference/expressions.html#operator-precedence
because looking @ wrong thing. call (or function call) takes higher precendence on both and > (greater than) . first function calls occur left right.
python results function calls before either comparison happens. thing takes precendence on here short circuiting , if test("first",10) returned false, short circuit , return false.
the comparisons , and still occur in same precendence , first result of test("second", 15) compared against test("third", 5) (please note return values (the function call occured before)) . result of test("second", 15) > test("third", 5) used in and operation.
from documentation on operator precedence -

Comments
Post a Comment