"Roy Chen" <[EMAIL PROTECTED]> wrote
> def f(a, L=[]):
>L.append(a)
>return L
This creates a single list object L used for all calls to f()
that don;t provide an explicit L. Thus each call appends
to the same object.
>
> def g(a, L=None):
> if L == None:
> L = []
> L.app
Roy Chen wrote:
> Hi everyone, been looking at the following functions, but can't
> figure out how they work.
>
> def f(a, L=[]):
> L.append(a)
> return L
>
> def g(a, L=None):
> if L == None:
> L = []
> L.append(a)
> return L
http://effbot.org/pyfaq
Hi everyone, been looking at the following functions, but can't
figure out how they work.
def f(a, L=[]):
L.append(a)
return L
def g(a, L=None):
if L == None:
L = []
L.append(a)
return L
print f(1)
print f(2)
print f(3)
print g(1)
print g