Member-only story

6 Boolean Things I’ve Observed In Production Python Code

Liu Zuo Lin
4 min read4 days ago

--

I’ve worked as a software engineer at 3 multinational companies thus far, and have observed lots of good (and bad) practices in Python. Here are some common observations I’ve made about booleans:

1) bool() is explicitly used sometimes

In production code, readability is often a prioritized and some programmers choose to write code more explicitly.

Here’s an example of how we might normally write our conditions:

However, when we have a whole bunch of conditions, I’ve seen some cases where bool() is explicitly used to make the code more readable.

Arguably, removing the bool() won’t affect the result of the code at all. But it does make it more immediately obvious that the entire condition should be a boolean value

2) Truthy/falsy values are used by themselves in conditions

--

--

Liu Zuo Lin
Liu Zuo Lin

Written by Liu Zuo Lin

SWE @ Meta | [Ebook] 101 Things I Never Knew About Python: https://payhip.com/b/vywcf

Responses (3)