Result of ``a is b''

Erik Max Francis max at alcyone.com
Tue Mar 16 19:43:31 EST 2004


Axel Boldt wrote:

> David MacQuigg <dmq at gain.com> wrote
> 
> > >>> x = 'akdijfkdienlskfi'
> > >>> y = 'akdijfkdienlskfi'
> > >>> x is y
> >  True
> > >>> x = 'a b'
> > >>> y = 'a b'
> > >>> x is y
> >  False
> 
> Wow. So it seems that the action of "is" on immutables is unspecified
> and implementation dependent, thus useless to the programmer.

It's less useful for testing mere equivalence, yes, because that's not
what it's intended to do.  It tests identity.  Here whether the two
strings are not just equal but _identical objects_ is an implementation
detail.  If you ever rely on this behavior, your code will not be
portable to other implementations of Python.

-- 
 __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
/  \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ Here day fights with night.
    -- (the last words of Victor Hugo)



More information about the Python-list mailing list