On Mar 10, 10:39 am, Gary Herron <[EMAIL PROTECTED]> wrote:
> 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.

Not quite: None is immutable but it's usually recommended to test for
it using is.


Carl Banks
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to