+ 1

[Python:OutputExplanation] Someone explain me output of this code. def func(a, L=[]): L.append(a) return(L)

I am confused with the output of this code def f(a,L=[]): L.append(a) return(L) print(f(3), f(4)) I am confused how is appended value to List L is memorized even after function exits? https://code.sololearn.com/czlOon5UjyaJ/#py

7th Jun 2018, 2:36 PM
Gopal Gautam
Gopal Gautam - avatar
2 Réponses
+ 3
i confuse too with your question. first that create a function with a and L (list) default argument than, a is inserted to L and finally return the L list.
7th Jun 2018, 3:55 PM
Kevin AS
Kevin AS - avatar