Logical operations

Report a typo

In Python, logical operators like and and or can stop checking values early, which is called short-circuit evaluation. This means Python may not check both parts of the expression if it already knows the result after looking at the first value.

  • With and: If the first value is False, Python doesn't need to check the second value because the whole expression will be False.

  • With or: If the first value is True, Python stops because the whole expression will be True.

Now, let's look at two boolean variables:

a = True 
b = False

For which expression will Python only check the first operand (i.e. short-circuit evaluation)?

Select one option from the list
___

Create a free account to access the full topic