im really confusing now, in my program thought model if you met an expression like these
expr = expr1 and expr2
which mean the expr’s type must be Boolean,same thing to ‘or’ operations
see the codes below, suppose the three lines will print booleans
print(1==1 and 3)
print(1==2 and 3)
print(1==2 and 3 or 4)
but the result is
3
False
4
i have to restudy the basic programming :
the true meaning of and and or
‘e1 and e2’ means evaluate e1 if the result is False return False else return e2
‘e1 or e2’ means evaluate e1 if the result is True return True else return e2
do i get it right?
This behaviour doesn’t really have to do with Boolean logic per se. Rather, it is peculiar to Python. Instead of always returning
True/False,andandorreturn the value of one of the two operands.The following is a good explanation: The Peculiar Nature of
andandor.