Python Language Boolean Operators `and` and `or` are not guaranteed to return a boolean

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

When you use or, it will either return the first value in the expression if it's true, else it will blindly return the second value. I.e. or is equivalent to:

def or_(a, b):
    if a:
        return a
    else:
        return b

For and, it will return its first value if it's false, else it returns the last value:

def and_(a, b):
    if not a:
        return a
    else:
        return b


Got any Python Language Question?