6 is 2 * 3
True
666 is 2 * 333
False
60 is 10 * 6
True
666 == 2 * 333
True

above is the result of my check
This is really weird!
I thought computers were absolute logic and didn't work like humans.
Looks like the programmers have included their idiosyncrasies to the
programs! Else how could this be possible?


On Mon, Jun 23, 2014 at 11:55 AM, Greg Ewing <greg.ew...@canterbury.ac.nz>
wrote:

> diliup gabadamudalige wrote:
>
>> Can someone please explain why  if event.type is KEYUP:
>>
>> is bad and
>>
>>  if event.type == KEYUP:
>>
>> is correct?
>>
>
> The 'is' operator tests whether two expressions refer to
> the *same* object. It's possible for two different int
> objects to have the same value, in which case 'is' and
> '==' will give different results, e.g.
>
> >>> 666 == 2 * 333
> True
> >>> 666 is 2 * 333
> False
>
> You can be misled if you try this experiment with
> sufficiently small integers, however:
>
> >>> 6 is 2 * 3
> True
>
> This happens because CPython keeps a cache of small
> integer objects and re-uses them. But that's strictly
> an implementation detail, and not something you
> should rely on. The only reliable way to tell whether
> two ints are equal is to use ==.
>
> --
> Greg
>



-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**********************************************************************************************
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**********************************************************************************************

Reply via email to