conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour))

James_Althoff at i2.com James_Althoff at i2.com
Mon Oct 15 19:30:35 CEST 2001


Paul Rubin wrote:
>"Tim Peters" <tim.one at home.com> writes:
>> Everything's cool if parens are required around a conditional
expression,
>> though, in which case:
>>
>>     x = if e1 then e2 else e3 + 1   # SyntaxError
>>     x = (if e1 then e2 else e3) + 1 # cool
>>     x = (if e1 then e2 else e3 + 1) # cool
>>     x = if e1 then e2 else e3       # SyntaxError
>>     x = (if e1 then e2 else e3)     # cool
>>     x = if if e1 then e2 else e3 then e4 else e5     # SyntaxError
>>     x = (if (if e1 then e2 else e3) then e4 else e5) # cool
>>
>> Seems a mixed bag, but I'm more interested in readability and the
>> functionality than in minimizing keystrokes; requiring parens doesn't
hurt
>> the goals I care about.
>
>It's more readable with the parentheses anyway.

I agree.

Jim






More information about the Python-list mailing list