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

Paul Rubin phr-n2001d at nightsong.com
Sun Oct 14 16:34:26 EDT 2001


"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.



More information about the Python-list mailing list