For review: PEP 308 - If-then-else expression

Bengt Richter bokr at oz.net
Mon Feb 10 12:00:11 CET 2003


On Mon, 10 Feb 2003 05:50:23 GMT, Andrew Koenig <ark at research.att.com> wrote:
[...]
>
>Erik> I must say I'm pretty convinced at this point that `if C: x
>Erik> else: y' (and if we wish, its multiway variants `if C: x elif D:
>Erik> y else: z') is absolutely the way to go if you want a
>Erik> conditional operator.
>
>I'd still be willing to live with `x if C else y', because I think
>it's much better than `C and x or y'.

IMO, if there is no multiway choice, you can't beat the conciseness of

    cond ? "Yep", "Nope"

(with parens optional except when needed for some disambiguation)
My only worry is using up "?" for something less than a best use.

Regards,
Bengt Richter




More information about the Python-list mailing list