Default method arguments

Mike Meyer mwm at
Tue Nov 15 21:33:32 CET 2005

gregory.petrosyan at writes:

> Hello everybody!
> I have little problem:
> class A:
>     def __init__(self, n):
> = n
>     def f(self, x = ????)
>         print x
> All I want is to make the default argument for self.f(). (I
> want to use 'A' class as following :

Store your default value in a container, and test for it:

class A:
    _data = [None]
    def __init__(self, n):
        self._data = [n]
    def f(self, x = _data):
        if x is self._data:
           x = x[0]
        print x
There are lots of variations on this theme.

Mike Meyer <mwm at>
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

More information about the Python-list mailing list