Re: [Tutor] Question about default values for arguments

2007-10-11 Thread Alan Gauld
"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

Re: [Tutor] Question about default values for arguments

2007-10-11 Thread Kent Johnson
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

[Tutor] Question about default values for arguments

2007-10-11 Thread Roy Chen
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