Python Tip #214 (of 365):
Use truthiness for integers with caution.
I DO rely on truthiness checks for integers, but not always. I would recommend only using them when they seem to improve readability.
I find this:
if hours: ...
More readable than this:
if hours > 0: ...
But I find this:
if number % 2 != 0: ...
More readable than this:
if number % 2: ...
🧵 (1/2)
#Python #DailyPythonTip
#214
1 posts · Last used Aug 03
You've seen all posts