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

Ben Finney ben+python at benfinney.id.au
Wed Nov 12 00:09:12 CET 2014


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

> I don’t necessarily see the difference as stated in the subject line.

The difference is: there is exactly one ‘True’ value, but many values
which *evaluate* true in a boolean context.

That is, many values (any non-empty string, any non-zero number, any
non-empty collection, most values of most types) are not equal to
‘True’; but will evaluate true when used in an ‘if’ or ‘while’ or other
boolean context.

So, the documentation stating “X has a value of True” leads to the
incorrect inference you drew, of expecting it to *compare equal to* True
(and, indeed, to be *identical to* True).

Whereas what the documentation needs to say is that the objects it is
referring to have values which *evaluate true* in a boolean context such
as ‘if’ or ‘while’. No implications about values being equal to other
values.

-- 
 \     “I went to the cinema, it said ‘Adults: $5.00, Children $2.50’. |
  `\          So I said ‘Give me two boys and a girl.’” —Steven Wright |
_o__)                                                                  |
Ben Finney



More information about the Tutor mailing list