Re: Does the "is" operator only matter for mutable object?
Nick Coghlan <[email protected]> Mon, 7 Mar 2011 10:30:08 +1000
| Newsgroups | gmane.comp.python.documentation |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Mar 7, 2011 at 9:08 AM, Laura Creighton <[email protected]> wrote: > Singleton objects such as ``True``, ``False``, and ``None`` are always > the same object. The canonical way to test whether an object is > a singleton is to test for object identity, not equality. So > >>>> if x is None: > ... do something ... > > not > >>>> if x == None: > ... do something ... Careful with that - "if x is True:" and "if x is False:" (along with s/is/==/) are almost always the wrong thing to do, but a reader could easily generalise the above to cover those two cases as well. Cheers, Nick. -- Nick Coghlan | [email protected] | Brisbane, Australia _______________________________________________ Doc-SIG maillist - [email protected] http://mail.python.org/mailman/listinfo/doc-sig