The and
and or
operators do return one of their operands, not a pure boolean value like True
or False
:
>>> 0 or 42
42
>>> 0 and 42
0
Whereas not
always returns a pure boolean value:
>>> not 0
True
>>> not 42
False
More Related Contents:
- How do “and” and “or” act with non-boolean values?
- Python: Does Python have a ternary conditional operator?
- “is” operator behaves unexpectedly with integers
- Bitwise operation and usage
- When is “i += x” different from “i = i + x” in Python?
- The tilde operator in Python
- What exactly does += do?
- How do you get the logical xor of two variables in Python?
- Python: defining my own operators?
- How can I obtain the element-wise logical NOT of a pandas Series?
- What does % do to strings in Python?
- “x not in y” or “not x in y”
- Python != operation vs “is not”
- How do I do exponentiation in python? [duplicate]
- Why is ” > 0 True in Python 2?
- assign operator to variable in python?
- Override Python’s ‘in’ operator?
- What is the motivation for the “or” operator to not return a bool?
- What does “ mean in Python?
- Modulo operator in Python
- Overloading Addition, Subtraction, and Multiplication Operators
- Is the behaviour of Python’s list += iterable documented anywhere?
- Python augmenting multiple variables inline
- What do these operators mean (** , ^ , %, //)? [closed]
- What is the difference between ‘+=’ and ‘=+’? [duplicate]
- Is there a short-hand for nth root of x in Python?
- How does Python implement the modulo operation?
- How does Python’s bitwise complement operator (~ tilde) work?
- Under what circumstances are __rmul__ called?
- Why should I use operator.itemgetter(x) instead of [x]?