[Doc-SIG] Does the "is" operator only matter for mutable object?

Aahz aahz at pythoncraft.com
Sat Mar 5 18:06:22 CET 2011


On Sat, Mar 05, 2011, INADA Naoki wrote:
>
> If detailed description is needed, my suggesting is:
> 
> """
> The operators ``is`` and ``is not`` compare whether two objects
> are really the same object.  Note that immutable objects having
> same value and type may be unified for efficiency.  For example,
> ``'spam' is 'spam'`` is either ``True`` or ``False`` depending on
> Python implementation.  Especially, singleton objects like ``True``,
> ``False``, ``None`` are always same object when thier type and value
> is same.
> """

+1 -- here's my rewrite for a bit more clarity:

The operators ``is`` and ``is not`` compare whether two objects are
really the same object (have the same memory location).  Immutable
objects with the same value and type may be cached to the same object for
efficiency.  For example, ``'spam' is 'spam'`` is either ``True`` or
``False`` depending on Python implementation.  Singleton objects
(``True``, ``False``, ``None``) are always the same object.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Programming language design is not a rational science. Most reasoning
about it is at best rationalization of gut feelings, and at worst plain
wrong."  --GvR, python-ideas, 2009-03-01


More information about the Doc-SIG mailing list