Boolean Operators in Python Aren’t What You Think

<p>I consider myself a decent Python programmer. I&rsquo;ve worked with the language extensively in the past and it&rsquo;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 &ldquo;huh&rdquo; 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&nbsp;<code>True and False</code>,&nbsp;<code>&quot;abc&quot; and &quot;&quot;</code>, and&nbsp;<code>None or 0</code>&nbsp;would all evaluate to&nbsp;<code>False</code>, owing to the fact that Python interprets&nbsp;<code>False</code>,&nbsp;<code>None</code>, empty strings, numeric zero of all types, as well as&nbsp;other values&nbsp;as false.</p> <p>And why wouldn&rsquo;t I think this? After all, we&rsquo;ve been using&nbsp;<code>if</code>&nbsp;statements forever and they&rsquo;ve never disappointed.</p> <p><a href="https://betterprogramming.pub/boolean-operators-in-python-arent-what-you-think-df45a2be71f1">Read More</a></p>