[Tutor] Question about default values for arguments

Kent Johnson kent37 at tds.net
Thu Oct 11 17:30:20 CEST 2007


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/why-are-default-values-shared-between-objects.htm

Kent


More information about the Tutor mailing list