FW: [Python-Dev] conditional expressions?

Tim Peters tim.one at home.com
Mon Oct 15 17:46:32 EDT 2001


[misattributed to me -- these are Guido's examples]
> Some examples where parentheses *are* required:
>
>     (if 1 then 2 else 3) + 4
>     a[(if i then 2 else 3) : 4]

[Paul Rubin]
> Hmmm, this looks error prone.  What happens if you omit the parentheses
> in these examples?

You get SyntaxErrors.  That's what "*are* required" means -- you use parens
in these cases or they don't fly at all.

>  Are they equivalent to
>
>    if 1 then 2 else (3+4)
>
> and
>
>    if i then a[2] else a[3:4]
>
> respectively?

If you don't use parens, they're equivalent to

    ]*** ) 3fo?rkl





More information about the Python-list mailing list