Last time, I talked about Python’s boolean operators
or and what can be confusing about them when “truthy” objects get into the mix. If you haven’t already read it, I would highly recommend it. This article is similar, but looks into something just a little different: the ability to string comparison operators.
The Confusing Code
Just like last time, we’ll start off looking at some code that confused someone enough to ask the community about it:
'a' in 'abc' # True
True == True # True
'a' in 'abc' == True # False
At a cursory glance, there seems to be something wrong with that it would come up with such a result. Continue Reading
To start, I’ll give an update on my video series. I’ve recorded my first episode, but I’ve had a ton of troubles when trying to edit it. The application keeps crashing, which is okay, since it recovers most of what I did, but it does grow tedious. I’ve also decided to start the editing over due to a few factors. Lastly, I’ve started recording a series of videos with my best friend for his gaming YouTube channel. All of that together has led me to put off the my video series for a while and get back to writing on the blog. I’ll get back to the video series when I’ve finished recording with my friend. It could take a while.
Python Boolean Operator Confusion
A while back, I stumbled upon a post asking about the how the following lines could possibly right:
'a' == 'b' or 'a' returns
'a' == 'a' and 'b' returns
He had a few other lines that did what you might expect, returning
False. But why do these
or operators not always return boolean values? To answer that, I’d like to dig into Python’s history. Continue Reading