question about True values

Donn Cave donn at u.washington.edu
Thu Oct 26 00:59:31 CEST 2006


In article <1161812827.596356.316450 at f16g2000cwb.googlegroups.com>,
 "John Coleman" <jcoleman at franciscan.edu> wrote:

> Very good point, though one could argue perhaps that when one is
> comparing an object with a truth value then one is implicitly asking
> for the truth value of that object

On the contrary -- since there is normally no need to ever
compare an object with a truth value, then I would interpret
this usage as an attempt to distinguish True or False from
other objects in general.  Some kind of placeholders for
missing values, who knows.  I'm not saying it's a great idea,
but it could work in recent versions of Python.

> This would make code like 'if s: ' equivalent
> to 'if s == True:' with a possible gain in readability. But - as you
> demonstrate the cost of that (minimal) gain in readability would be too
> high. In any event - I think it is mostly bad style to use a
> non-boolean variable in 'if s:' - it reminds me too much of obscure C
> code (though others might disagree).

Others will indeed disagree.  I don't think you'll find
much support for this position.  But it's not as bad as
your notion that "if s == True", where s is not a boolean
object, might represent a gain in readability.  That really
redefines readability.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list