retain values between fun calls

Gary Wessle phddas at
Sun May 14 00:53:33 CEST 2006


the second argument in the functions below suppose to retain its value
between function calls, the first does, the second does not and I
would like to know why it doesn't? and how to make it so it does?


# it does
def f(a, L=[]):
    return L
print f('a')
print f('b')

# it does not
def f(a, b=1):
    b = a + b
    return b
print f(1)
print f(2)

More information about the Python-list mailing list