On Thu, 10 Feb 2005, Ismael Garrido wrote:
> Danny Yoo wrote:
>
> >###
> >
> >def f(a,L=[]):
> > if L==[5]:
> > print 'L==[5] caught'
> > print L
> > print 'resetting L...'
> > L=[]
> > L.append(a)
> > return L
> >###
> >
> Now I'm dizzy... I can't understand why there are two "L"!
Hi Ismael,
Ok, let's ignore the default argument stuff for the moment.
Let's change the program slightly, to the following:
###
someList = []
def f(a):
L = someList
if L == [5]:
print "L == [5] caught"
print L
print "Resetting L..."
L = []
L.append(a)
return L
###
Try out Jeffrey's experiments, and see if you see anything unusual. Does
what you see make sense to you, or is it still baffling?
Please feel free to ask questions, and we'll go from there. Best of
wishes to you!
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor