I know that the AND operator has precedence over the OR operator. I also believe that like in C/CPP the associativity of these operators is from left to right (although it doesn't seem to be crucial for my question).
I run the following code in Python 2.7.1:
Case 1:
I have three functions:
def f(): print 3; return True
def g(): print 4; return False
def h(): print 5; return False
When I run the following command
f() and g() or h()
I get
3
4
5
False
This is fine (what I expected).
Case 2:
If I change the functions to:
def f(): print 3
def g(): print 4
def h(): print 5
I get for the same command:
3
5
Case 3:
If I change the command to
f() and (g() or h())
I get only:
3
I know that in the last two examples, the functions do not actually return boolean value, but yet - I don't understand this behavior. it seems inconsistent:
Do we refer the functions f(),h(),g() as True or as False or something alse (what?)?
Why in the second case, h() runs and not g()?
Why in the last case none of them (g and h) run?