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

Clayton Kirkwood crk at godblessthe.us
Wed Nov 12 04:23:11 CET 2014


 

 

From: Tutor [mailto:tutor-bounces+crk=godblessthe.us at python.org] On Behalf Of Danny Yoo
Sent: Tuesday, November 11, 2014 5:25 PM
To: Ben Finney; tutor at python.org
Subject: Re: [Tutor] “has a value of True” versus “evaluates true”

 

 

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

"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.

 

Thanks, Danny, that’s kind of the thing I learned about this whole issue. Force the issue truth by casting. Don’t know if I’ll always keep it, but that seems prudent. What led to a portion of this whole issue was that I was assuming that equal sign assignment would produce a True/False certainty which could be tested. I vaguely recall this premise in another language, probably C or Perl.

 

Truthfully,

 

Clayton

 

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

 

:P

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141111/18e2e088/attachment-0001.html>


More information about the Tutor mailing list