2

I am new to python and I am not able to understand the 3rd output below. How does it work?

def f(x,l=[]):
    for i in range(x):
        l.append(i*i)
    print(l)

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

output:

[0, 1]
[3, 2, 1, 0, 1, 4]
[0, 1] ---> How does it get the list from the f(2) output? 
            even though we have changed it with f(3,[3,2,1])
Sreeraj Chundayil
  • 5,548
  • 3
  • 29
  • 68

0 Answers0