How exactly does Python evaluate statements connected by multiple and/or operators?
When I run the following statement in Python:
[1] or [] and (1,) or ()
the output is [1].
But for the below statement,
[] or [1] and (1,) or ()
the output is (1,).
I am confused. What causes the difference in outputs for both statements? What is the order of evaluation here?
In "or" operator when one of the condition is true then it returns "True" if the both conditions are false it returns "False"
So with your first condition: "1 or [] and (1,) or ()"
In "and" operator it returns "True" when both the conditions are true if one of the conditions is false then it returns "False"
Same goes with your second condition [] or 1 and (1,) or ()
Note: T for "True" F for "False"For reference you can go through this link