Python complaints
Gareth McCaughan
Gareth.McCaughan at pobox.com
Wed Nov 24 17:23:14 EST 1999
Gordon McMillan wrote:
[I said:]
>> - if/then/else works on *statements* (strictly, suites of
>> statements) rather than on *expressions*, so I can't
>> say
>> 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')
> ...
>>>> p(1)
> You scored 1 point
>>>> p(3)
> 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
mailing list