What value should be passed to make a function use the default argument value?
Stan Graves
stanley.graves at gmail.com
Tue Oct 3 17:15:12 EDT 2006
LaundroMat wrote:
> Suppose I have this function:
>
> def f(var=1):
> return var*2
>
> What value do I have to pass to f() if I want it to evaluate var to 1?
> I know that f() will return 2, but what if I absolutely want to pass a
> value to f()? "None" doesn't seem to work..
What about this?
>>> def f(var=None):
... if var == None:
... var = 1
... return 2*var
...
>>> f()
2
>>> f(3)
6
>>> a=4
>>> f(a)
8
>>> b=None
>>> f(b)
2
>>>
--Stan Graves
More information about the Python-list
mailing list