Python `or`, `and` operator precedence example
问题 I cannot produce example in Python which shows Boolean operator precedence rules combined with short circuit evaluation. I can show operator precedence using: print(1 or 0 and 0) # Returns 1 because `or` is evaluated 2nd. But the issue with short circuiting shows up when I change it to this: def yay(): print('yay'); return True def nay(): print('nay') def nope(): print('nope') print(yay() or nay() and nope()) # Prints "yay\nTrue" For each of 4 possibilities when expression before or is True