Notes
The and and or are the short circuit operators. They stop evaluating when they have sufficient information instead of evaluating all of its operands.
Examples 1
if 1==1 or this_function_does_not_exist():
print("surprise!")
#You may expect that an error may occur because the program calls a function this_function_does_not_exist() that is not defined;
#but surprisingly the program print the words "surprise!" successfully. Why?
#Well because 1==1 is true. For the or operator, it determines that it has enough information to produce a true output, so it is not necessary to evaluate the this_function_does_not_exist() function.
Examples 2
if not (1==0 and this_function_does_not_exist()):
print("surprise!")
#Again, You may expect that an error may occur because the program calls a function this_function_does_not_exist() that is not defined;
#but surprisingly the program print the words "surprise!" successfully. Why?
#Well because 1==0 is false. For the and operator, it determines that it has enough information to produce a false output, so it is not necessary to evaluate the this_function_does_not_exist() function.