[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Re: Inconsistent Constant Comparison
- To: pygame-users@seul.org
- Subject: [pygame] Re: Inconsistent Constant Comparison
- From: Pete Shinners <pete@shinners.org>
- Date: Wed, 08 Oct 2003 15:21:37 -0700
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Wed, 08 Oct 2003 18:24:09 -0400
- Reply-to: pygame-users@seul.org
- Sender: owner-pygame-users@seul.org
- User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5) Gecko/20030916
> >>> K_6
> 54
> >>> 54 is K_6
> True
> >>> K_KP4
> 260
> >>> 260 is K_KP4
> False
>
> Is this due to some inconsistency in the way
> the constants were declared?
This is actually do to some sneaky internal optimization by the Python
interpreter. low integer values are cached objects, so they always refer
to the same object. higher integer objects are instanced like regular
python objects, so they do not refer to the same objects.
>>> 2+2 is 4
True
>>> 100+100 is 200
False
the moral of the story is, use the equals operator to compare integers
(and the pygame constants, which are integers)