While trying to debug an issue, I hit some weird boolean evaluation happening in python. Below is the sample shell result.
In [4]: True or False and False
Out[4]: True
In [5]: False or True and False
Out[5]: False
What exactly is happening here. Shouldn't both evaluate to the same result?
and binds tighter than or, so what you're writing is actually
In [4]: True or (False and False)
Out[4]: True
In [5]: False or (True and False)
Out[5]: False
and takes precedence over or. See what happens when we evaluate the and first?
>>> (True or False and False) == (True or False)
True
>>> (False or True and False) == (False or False)
True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With