Fred L. Drake, Jr.
fdrake at acm.org
Wed Nov 24 09:50:26 EST 1999
Gordon McMillan writes:
> >>> def p(score):
> ... print "You scored %d point%s" % (score, score==1 and ' '
> or 's')
The catch is that this only works when the result value for the true
case is also true. I often find I want this sort of construct when
the true result is either false or may be either. The hack to get
x = (some.test and [v1] or [v2])
is really nasty in practice, so I find it's typically *far* more
reliable to expand it out to a full-fledged if:
x = v1
x = v2
Much longer, but more reliable given the lack of ?: (which I'd also
like to see added, though I'm not sure what the syntax should be).
Fred L. Drake, Jr. <fdrake at acm.org>
Corporation for National Research Initiatives
More information about the Python-list