Boolean Operators in Python Aren’t What You Think
<p>I consider myself a decent Python programmer. I’ve worked with the language extensively in the past and it’s the one I generally feel most comfortable using.</p>
<p>But even well within the cozy confines of our comfort zones, every now and then, we all come across energizingly unfamiliar “huh” moments. Recently, I had one such moment and it came from where one might least expect it: good old Boolean operators.</p>
<p>You see, until that point, I was under the impression that the expressions <code>True and False</code>, <code>"abc" and ""</code>, and <code>None or 0</code> would all evaluate to <code>False</code>, owing to the fact that Python interprets <code>False</code>, <code>None</code>, empty strings, numeric zero of all types, as well as other values as false.</p>
<p>And why wouldn’t I think this? After all, we’ve been using <code>if</code> statements forever and they’ve never disappointed.</p>
<p><a href="https://betterprogramming.pub/boolean-operators-in-python-arent-what-you-think-df45a2be71f1">Read More</a></p>