pygame question

jepler at unpythonic.net jepler at unpythonic.net
Thu Jul 11 19:43:22 EDT 2002


On Thu, Jul 11, 2002 at 05:58:18PM -0500, Michael Bauers wrote:
> I was curious as to why 'is K_SPACE' worked, but 'is K_r' did not.  I had to
> change the test for 'r' to ==.
> 
> * code snippet *
>             elif (event.type is KEYDOWN and event.key is
>                K_SPACE):
>                 # DO SOMETHING
>             elif (event.type is KEYDOWN and
>                   event.key == K_r):
>                # DO SOMETHING ELSE

If these are just ints, you should use ==, not 'is'.

'is' will work sometimes, and more often for small positive ints (they're
special).

>>> x = 1000
>>> x is 1000
0
>>> x = 1       
>>> x is 1
1

Jeff





More information about the Python-list mailing list