True inconsistency in Python

Ron Adam radam2 at tampabay.rr.com
Fri Nov 14 00:59:20 CET 2003


On Thu, 13 Nov 2003 00:19:31 -0800, "Michael Geary"
<Mike at DeleteThis.Geary.com> wrote:

>Ron Adam:
>> The only thing that surprises me in all of this is the
>> "if var:" evaluating to true for numbers other than 1.
>> That's new to me,  I would have expected an
>> exception in that case.  But it still makes since if I
>> look at it as a shortcut for  "if (var != 0):".    This only
>> proves I'm still relatively new to Python I think.
>
>It's handy, and natural in many real life situations, to treat any nonzero
>value as "true". For example:
>
>Do you have any money in your wallet?
>
>Do you have children?
>
>I could ask how much money or how many children you have, but if I just ask
>the yes-or-no question, you'll naturally answer "yes" for any nonzero value.
>
>Of course, if you have children, you won't have money, but that's a separate
>problem...
>
>-Mike
>

That makes since,  Thanks for clarifying this.

I learned boolean logic as part of a computer tech degree back in
early 80's.  Binary logic circuits use only 0 and 1.  So it's the way
I think when dealing with bool type.  

_Ron Adam





More information about the Python-list mailing list