is operator
Matt Nordhoff
mnordhoff at mattnordhoff.com
Mon Mar 10 05:35:29 EDT 2008
Metal Zong wrote:
> The operator is and is not test for object identity: x is y is true if
> and only if x and y are the same objects.
>
>>>> x = 1
>>>> y = 1
>>>> x is y
> True
>
> Is this right? Why? Thanks.
I believe Python automatically creates and caches int objects for 0-256,
so whenever you use them, they refer to the same exact objects. Since
ints are immutable, it doesn't matter.
--
More information about the Python-list
mailing list