A certainl part of an if() structure never gets executed.

Nick the Gr33k support at superhost.gr
Sun Jun 16 04:20:03 EDT 2013


On 16/6/2013 4:55 πμ, Tim Roberts wrote:
> Nick the Gr33k <support at superhost.gr> wrote:
> Because Python lets you use arbitrary values in a Boolean context, the net
> result is exactly the same.

What is an arbitrary value? don even knwo what arbitrary means literally 
in English.

> In a long series separated by "or", the expression is true as soon as one
> of the subexpressions is true.  So, as a short-circuit, Python simply
> returns the first one that has a "true" value.  So, for example, these all
> return 'abcd':
>
>      'abcd' or 'defg' or 'hjkl'   ==> 'abcd'
>      0 or 'abcd' or 'defg' or 'hjkl'  ==> 'abcd'
>      0 or None or 'abcd' or 'defg' or 'hjkl'  ==> 'abcd'
>
> Similarly, "and" returns the first "false" value, or if they're all true,
> the last value.  Why?  Because it can't know whether the whole expression
> is true unless it looks at every value.  So:
>
>      0 and 1 and 'what'   ==>  0
>      1 and 0 and 'what'   ==>  0
>      1 and None and 0     ==>  None
>      1 and 1 and 'what'   ==> 'what'
>
Thank you Tim.

I decided that it's better to thing it through as:

The argument being returned in an "and" or "or" expression is the one 
that *determined' the evaluation of the expression.

And actually what's being returned is not the argument itself but the 
argument's value.

-- 
What is now proved was at first only imagined!



More information about the Python-list mailing list