[Info] PEP 308 accepted - new conditional expressions

Reinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
Sat Oct 1 02:25:39 EDT 2005


Ron Adam wrote:

>> It will be
>> 
>> A if B else (C if D else F)
> 
> So this evaluates as if there are parentheses around each section.. Hmm?
> 
>    (A) if (B) else ( (C) if (D) else (F) )
> 
> The first 'if' divided the expr, then each succeeding 'if' divides the 
> sub expressions, etc...  ?
> 
> So ...
> 
>    A if B else C + X * Y
> 
> Would evaluate as... ?
> 
>    A if B else (C + X * Y)
> 
> 
> and...
> 
>     value = X * Y + A if B else C
> 
> would be ?
> 
>     value = (X * Y + A) if B else C
> 
> or ?
> 
>     value = X * Y + (A if B else C)
> 
> 
> 
> I think I'm going to make it a habit to put parentheses around these 
> things just as if they were required.

Yes, that's the best way to make it readable and understandable.

Reinhold



More information about the Python-list mailing list