[Info] PEP 308 accepted - new conditional expressions

Chris Smith smitty_one_each at bigfoot.com
Thu Oct 13 23:35:59 CEST 2005


>>>>> "Duncan" == Duncan Booth <duncan.booth at invalid.invalid> writes:

    Duncan> Chris Smith wrote:
    >> What I really want to do is take four lines of conditional, and
    >> put them into one, as well as blow off dealing with a 'filler'
    >> variable:
    >> 
    >> return "the answer is " + "yes" if X==0 else "no"
    >> 
    >> 
    >> Or whatever the final release syntax is.

    Duncan> The syntax is fine, but the semantics might not be what
    Duncan> you expected. If I understand it correctly you need:

    Duncan> return "the answer is " + ("yes" if X==0 else "no")

    Duncan> Guido's pronouncement said:

    >> In general, 'if' and 'else' bind less tight than everything
    >> except lambda.
I say, with the utmost arrogance, that I won't neglect the parens more
than, say, 50 times. ;)
-Chris



More information about the Python-list mailing list