and and or are not guaranteed to return a boolean
suggest changeWhen 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
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents