>>> a = False + 5
5
>>> a = not(1) + 5
False
As above, when False
is directly calculated, it will be calculated as 0
.
When using the logical operator not
, the value of not(1)
is False
or 0
.
But why does the result of directly putting not(1)
into the arithmetic operation and then calculating it again is False
?
Is this related to Python’s algorithmic logic?
Because
not
is not afunction
, but anexpression
. No matter younot(1)+5
ornot (1+5)
, its function is just to invert the subsequent result. .For example:
Usage of
not
operator in Python Boolean Operations:In addition, the precedence of the
+
operator is higher than that of thenot
operator, so innot(1) + 5
,(1) + 5
is calculated first, and then(1)+5
serves as the operand of thenot
operator. For example, you can see: