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

John Roth johnroth at ameritech.net
Sun Oct 14 19:08:44 EDT 2001


"Paul Rubin" <phr-n2001d at nightsong.com> wrote in message
news:7xu1x22c6l.fsf at ruckus.brouhaha.com...
> "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.

Exactly my thought. Less chance for the eye seeing what it wants to.

John Roth





More information about the Python-list mailing list