Python Tip #214 (of 365): Use truthiness for integers with caution. I DO rely on...

@treyhunner@mastodon.social

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