[Tutor] “has a value of True” versus “evaluates true”

Danny Yoo dyoo at hashcollision.org
Wed Nov 12 02:25:15 CET 2014

On Tue Nov 11 2014 at 3:09:38 PM Ben Finney <ben+python at benfinney.id.au>

> "Clayton Kirkwood" <crk at godblessthe.us> writes:
> > So, there is a difference between None and False, is that the issue?
> Yes. Those two values are different and not equal; but both evaluate
> false in a boolean context.

Just to note; not all programming languages do it this way.  Python is
fairly permissive in what it allows to be "truthy".  See:
https://plus.google.com/+ShriramKrishnamurthi/posts/4qvvKYC1R8Y for a brief
survey of what many other programming languages do.

It can be confusing and bug-prone as heck.

For myself, I usually want as restrictive an approach as possible with
respect to what things are considered "truthy".  If I'm in a boolean
context, I will explicitly make the expression being tested be either True
or False, and that's it.  That way, I know I won't get into shaky waters.
I program in multiple languages: I don't want to spend brain power
remembering yet another a truth table about truth.

To quote: "Let your statement be: 'Yes, yes', or "no, no': anything beyond
these is of evil."

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141112/02be9045/attachment.html>

More information about the Tutor mailing list