Beginner Question
Marcin Rak
mrak at sightlineinnovation.com
Wed Jun 1 20:55:14 EDT 2016
Hi to all
I have a beginner question to which I have not found an answer I was able to understand. Could someone explain why the following program:
def f(a, L=[]):
L.append(a)
return L
print(f(1))
print(f(2))
print(f(3))
gives us the following result:
[1]
[1,2]
[1,2,3]
How can this be, if we never catch the returned L when we call it, and we never pass it on back to f???
Any help is appreciated.
Marcin
More information about the Python-list
mailing list