Try:
id(a), id(b)
In some cases they are different objects, and "a is b" rightly evaluates
to False.
Gumm
On 6/23/2014 00:39, diliup gabadamudalige wrote:
when you say a=100 and b=100 it is understood that a and b are both
given TWO values and that both are the same is a coincidence.
BUT if that is the case how can a is b be TRUE for small integers and
a is b False for large integers? What logic is Python using here?
On Mon, Jun 23, 2014 at 1:07 PM, diliup gabadamudalige
<dili...@gmail.com <mailto:dili...@gmail.com>> wrote:
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
<mailto: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.
**********************************************************************************************
--
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.
**********************************************************************************************