[Info] PEP 308 accepted - new conditional expressions
Duncan Booth
duncan.booth at invalid.invalid
Wed Oct 12 07:17:46 EDT 2005
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.
The syntax is fine, but the semantics might not be what you expected. If I
understand it correctly you need:
return "the answer is " + ("yes" if X==0 else "no")
Guido's pronouncement said:
> In general, 'if' and 'else' bind less tight than everything except
> lambda.
More information about the Python-list
mailing list