Gareth.McCaughan at pobox.com
Wed Nov 24 23:23:14 CET 1999
Gordon McMillan wrote:
>> - if/then/else works on *statements* (strictly, suites of
>> statements) rather than on *expressions*, so I can't
>> print "You scored %s point%s" % (score, if score==1 then ""
>> else "s")
>> or anything like that. (Or, as some people prefer to put it,
>> Python has no ? : operator.)
>>>> def p(score):
> ... print "You scored %d point%s" % (score, score==1 and ' '
> or 's')
> You scored 1 point
> You scored 3 points
Yes. Unfortunately, as we all know, this doesn't work when
it's (say) 1 and 0 you're choosing between instead of "s" and ""...
Gareth McCaughan Gareth.McCaughan at pobox.com
sig under construction
More information about the Python-list