Geek Culture
Published in

Geek Culture

The Hidden Traps of Python Truthy Values

And how to avoid them.

Photo by John McArthur on Unsplash

A truthy value is a value that is considered True when used in a boolean context. A falsy value is a value that is considered False when used in a boolean context. This is a useful feature of Python and several other languages.

They are very useful for writing concise and uncluttered code. But they come with a hidden danger to trap the unwary.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Martin McBride

Martin McBride

Software developer. Java, Python, C++ etc. I write for pythoninformer.com and maintain the generativepy library.