and and or are not guaranteed to return a boolean

suggest change

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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Boolean Operators:
*and and or are not guaranteed to return a boolean

Table Of Contents
31Set
65Boolean Operators
166Gzip