+ 1
Clarification on global and local scope of list.
def fuc(a,L=[]): L.append(a) return L print(fuc(1),fuc(3)) Ans : [1,3],[1,3] Both fuc(1) and fuc(3) return same result. WHY??
2 Respuestas
+ 1
Your print statement processes both fuc() calls before invoking print. try printing fuc(1) and then printing fuc(3) on a different line.
0
Most probably the comma in the print statement is indicating something like parallelism. Both fuc(1) and fuc(3) starts at the same time and founds a similar local scope like the one they were going to make. Then, thinking that local scope as their own they appends their input 'a' to the same list, L. At last python takes both the output from the same scope and just prints the same.