1 > 0 == True -> False

Ian Kelly ian.g.kelly at gmail.com
Thu Jan 30 15:28:07 EST 2014


On Thu, Jan 30, 2014 at 1:08 PM, Dave Angel <davea at davea.name> wrote:
>  Rotwang <sg552 at hotmail.co.uk> Wrote in message:
>> Really? I take advantage of it quite a lot. For example, I do things
>> like this:
>>
>> 'You have scored %i point%s' % (score, 's'*(score != 1))
>>
>
> I also did that kind of thing when computer resources
> were more
>  precious the program readability.  Like in 73 when my satellite
>  navigation system had to fit in 2k code and 1.5k
>  data.
>
> Here I'd probably do something like
>
> 'You have scored {} {}' .format (score, 'point' if score==1 else
>  'points')

Of course if you're at all concerned about i18n then the proper way to
do it would be:

ngettext("You have scored %d point", "You have scored %d points", score) % score



More information about the Python-list mailing list