6 is 2 * 3True666 is 2 * 333False60 is 10 * 6True666 == 2 * 333Trueabove is the result of my checkThis 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.ewing@xxxxxxxxxxxxxxxx> wrote:
diliup gabadamudalige wrote:The 'is' operator tests whether two expressions refer to
Can someone please explain why Âif event.type is KEYUP:
is bad and
Âif event.type == KEYUP:
is correct?
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.
**********************************************************************************************