[Tutor] "x and y" means "if x is false, then x, else y"??

Richard D. Moores rdmoores at gmail.com
Mon Jul 5 13:53:58 CEST 2010


On Mon, Jul 5, 2010 at 04:09, Stefan Behnel <stefan_ml at behnel.de> wrote:
> Richard D. Moores, 05.07.2010 11:37:
>>
>> I keep getting hung up over the meaning of "the return
>> value" of an expression. I am of course familiar with values returned
>> by a function, but don't quite grasp what the return value of, say,
>> the y of "x and y" might mean.
>
> Think of a different expression, like "1+1". Here, the return value (or
> maybe a better wording would be the result value) is 2.
>
>
>> Also, you distinguish between a return value of True and and the value
>> of y being such (say 5, and not 0) that it makes y true (but not
>> True). So another  thing I need to know is the difference between True
>> and true.  Also between False and false. And why the difference is
>> important.
>
> "True" is the value "True" in Python, which is a singleton. You can test for
> it by using
>
>    x is True

Ah. But could you give me an x that would satisfy that? I can think of

>>> (5 > 4) is True
True

But how can (5 > 4) be an x? Could you show me some code where it could be?

>>> x = (5 > 4)
>>> x
True
>>> x is True
True

So it can! That surprised me.  I was expecting   "x = (5 > 4)"  to be
absurd -- raise an exception? Still seems pretty weird.

> However, other values can have a true values as well, without being True,
> e.g.
>
>    if 1: print("TRUE!!!")
> will actually print the string, as the value 1 is considered true when turned
> into a boolean result.

Yes, I see that.

Well, maybe I'm getting there.

Thanks,

Dick
--------------
CAUTION: Pseudo Vorticity Advection


More information about the Tutor mailing list