Python Forum

Full Version: List in function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
def f(x,l=):
for i in range(x):
l.append(i*i)
print(l)

f(2)
f(3,[3,2,1])
f(3)


[0, 1]
[3, 2, 1, 0, 1, 4]
#How this is possible?
[0, 1, 0, 1, 4]
Please explain