What will be the output here?

Viewed 21
def make(x,y=[]):
    y.append(x)
    print(y)

for i in [5,8,20,2]:
    if i not in [10,20,30]:
        make(i)
    else:
        make(i,["A","B","C"])

Isn't the y list inside make() supposed to be disposed of by the interpreter after the code int the function gets executed?

Because when I run this, I get:

[5]
[5,8]
[A,B,C,20]
[5,8,2]

I was expecting the output to look like:

[5]
[8]
[A,B,C,20]
[2]

Can someone explain this to me?

0 Answers
Related