1 > 0 == True -> False
Dave Angel
davea at davea.name
Thu Jan 30 15:08:41 EST 2014
Rotwang <sg552 at hotmail.co.uk> Wrote in message:
> On 30/01/2014 12:49, Dave Angel wrote:
>> [...]
>>
>> For hysterical reasons, True and False are instances of class
>> bool, which is derived from int. So for comparison purposes
>> False==0 and True==1. But in my opinion, you should never take
>> advantage of this, except when entering obfuscation
>> contests.
>
> 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')
--
DaveA
More information about the Python-list
mailing list