RT @veervrrr
In Python, True is 1, False is 0, and 2 is true.

(Thank @mayuutann for showing me that 2 is truthy)

@worldsendless Any number but 0 is true. Any list / tuple / set / dictionary / string but the empty one is true.

@worldsendless 0 is false -- it's the only number that is.

I don't know that it's as much compatibility as letting programmers say "if x" rather than "if x != 0", "if data" rather than "if len(data) > 0", etc.

freecodecamp.org/news/truthy-a

Follow

@peterdrake as a happy Clojure dev I find myself wondering, why should developers want to write "if x != 0"? Why is it any better than "if x != 'cat'"? And why should language designers treat it specially?

@worldsendless I can't cite any evidence, but it seems like there are many situations where you want to do something only if a value is not zero or empty. Certainly you often want to check if x == null before you try to access x's fields or methods.

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.