is and == (is not other_thread)

Fredrik Lundh fredrik at pythonware.com
Thu Mar 1 01:26:58 EST 2001


Grant Griffin wrote:
> 1) Are two strings that are equal in the "==" sense always
> guaranteed to be equal in the "is" sense?

no.

> 2) Is "is" faster than "==" for strings?

marginally.  "==" executes a bit more C code before it
gets to the identity test.

> 3) Internally, does "==" for strings always begin with an "is"
> operation?

yes

for the details, see cmp_outcome in Python/ceval.c, and
PyObject_Compare in Objects/Object.c.

Cheers /F

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list