@diliup: It's because python's* is *operator checks if the two item is the same, and == checks for equality. Also python stores an object for the numbers from -5 to 255 to speed up things. Check it: a = 255 b = 255 print a is b print id(a), id(b) a = 256 b = 256 print a is b print id(a), id(b)
Hope it clears up some things! 2014-06-23 9:37 GMT+02:00 diliup gabadamudalige <dili...@gmail.com>: > ok > look at this! > a = 100 > b = 100 > a == b > True > a is b > True > a = 1000 > b = 1000 > a is b > False > a == b > True > > what on earth is this? what is this logic? > > > On Mon, Jun 23, 2014 at 1:03 PM, Sam Bull <sam.hack...@sent.com> wrote: > >> On lun, 2014-06-23 at 11:45 +0530, diliup gabadamudalige wrote: >> > I called event.clear() cause it says in the Pygame documentation that >> > if you leave unused events on the buffer that eventually it may fill >> > up and cause the program to crash. >> >> Yes, but if you are getting everything from the buffer using event.get() >> or whatever every frame, then it's not going to fill up, as these >> returned events are removed from the queue. As long as you are reading >> the whole buffer, say every 100ms, you're going to be fine. Otherwise, >> you're just throwing away the events that have arrived between the >> event.get() and event.clear() calls. >> >> > >> > if x is True: >> > is not correct >> > >> > if x == True >> > is correct? >> >> This obviously depends on what x is. >> >> So, if we write: >> "foo" is True >> >> We can clearly see these are not the same object. One is a string, and >> the other is the True object. But, if we do: >> "foo" == True >> >> Then, we are asking if the string evaluates to a True value, when >> treated as a boolean. And any non-empty string will be considered True, >> and so it is equal to True (but not the same object). >> >> >> Futhermore, what Greg was saying is that some objects can be of the same >> value and still not be the same object. Thus: >> a = 4040 >> b = 4040 >> a == b # True >> a is b # Could be False >> >> b = a # b now references the a object itself >> a is b # Always True >> >> This becomes more obvious if we were to use mutable types: >> a = [2] >> b = [2] >> # Obviously, these are two distinct objects >> a == b # True >> a is b # False >> # Changing one, would not change the other, as they are >> different >> # objects. >> a.append(3) >> a == b # False >> >> >> On an interesting sidenote, it is not even required that an object is >> equal to itself: >> a = float("NaN") >> a == a # False >> > > > > -- > 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. > > ********************************************************************************************** > >