Python FAQ: Equality
me.veekun.com
me.veekun.com
Not quite. SomeClass can have an implementation of __new__ which returns the same object upon every invocation. In this case "SomeClass() is SomeClass()" will be True. People sometimes do this and call SomeClass a "singleton".
http://effbot.org/zone/default-values.htm
In short, it can be bad to set default arguments to mutable objects because the function keeps using the same object in each call.
>>> u"" > () > "" == u""
TrueCPython implementation detail: Objects of different types except numbers are ordered by their type names; objects of the same types that don’t support proper comparison are ordered by their address.
>>> "" > ()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: str() > tuple()In most real cases you want to get out if arg is either None offer any false value, so maybe "if not arg" ?
> For testing whether two classes, functions, or modules are the same object, is is okay. Stylistic choice.
If "is" is not better than = I would advise against it in all cases where it is not necessary: always use = except when you do tricky things. The argument that = can be overridden is wrong: if it really is the case, just use another library or fix it. You should nor write defensive code at this level.