Common Mistake of Logic Operation in Python
When it comes to logic operation in programming, I usually think about &
or &&
. However, it can only work as a logic operator when the data type is boolean in Python. For the other secenario, simply using and
is the right way. If you encounter an error about datatype in a logic operation, please pay attention to this.
There is another fun fact that the &
operator has higher precedence than the and
operator.
This post is licensed under CC BY 4.0 by the author.