All answers suggesting None are correct; if you want to make sure that the caller can pass None as a normal argument, use the special sentinel and test with is :
class Foo(object): __default = object() def foo(self, blah=Foo.__default): if blah is Foo.__default: blah = self.instavar
Each call to object() creates a unique object, so is will never be successful between it and any other value. The two underscores in __default mean “highly private”, which means that callers know that they should not try to deal with it (and this will require some work, clearly mimicking the name that the compiler does).
The reason you cannot just use the code you entered is, by the way, the default values that are evaluated when the def statement evaluates, and not later during the call; and at time def , there is as yet no self from which to take an instance variable.
Alex martelli
source share