[Info] PEP 308 accepted - new conditional expressions

Roy Smith roy at panix.com
Wed Oct 12 19:26:58 CEST 2005

Chris Smith  <smitty_one_each at bigfoot.com> 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"

I would write this as:

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

Adding the parens makes it clearer.  I've long since given up trying
to remember operator precedence (except for the most basic like
multiplication is stronger than addition) and use parens with wild

More information about the Python-list mailing list