is operator
Gary Herron
gherron at islandtraining.com
Mon Mar 10 15:39:25 CET 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.
>
>
>
Yes that is true, but it's an implementation defined optimization and
could be applied to *any* immutable type. For larger ints, such a thing
is not true.
>>> x=1000
>>> y=1000
>>> x is y
False
If either is a surprise, then understand that the "is" operator should
probably *never* be used with immutable types.
Gary Herron
More information about the Python-list
mailing list