String Identity Test

Benji York benji at benjiyork.com
Tue Nov 1 09:04:38 EST 2005


Thomas Moore wrote:
> I am confused at string identity test:

>>>>a="test"
>>>>b="test"
>>>>a is b
> 
> True

> About identity, I think a is not b, but "a is b" returns True.
> Does that mean equality and identity is the same thing for strings?

Nope:

 >>> a = 'te' + 'st'
 >>> b = 'test'
 >>> a is b
False

You're seeing a coincidence of the implementation.
--
Benji York



More information about the Python-list mailing list