Result of ``a is b''
Asun Friere
afriere at yahoo.co.uk
Tue Mar 16 22:53:29 EST 2004
Skip Montanaro <skip at pobox.com> wrote in message news:<mailman.52.1079472192.742.python-list at python.org>...
> No, its behavior is quite well-specified. It does a pointer comparison.
> Here is my "is" rule:
>
> Use "is" to compare two objects only if one is explicitly known to be a
> singleton defined by the language (None, Ellipsis, True, False).
>
> and its corrolary:
>
> Never use "is" to compare two programmer-defined variables.
>
What about when it is an object explicitly known to be singleton
defined by the programmer. ;)
Another possible use, would be to type test, eg. 'foo.__class__ is
Foo', bearing in mind that one should avoid type testing in favour of
polymorphism.
More information about the Python-list
mailing list