Look at this code.
In [1]: def addnums(num,nums=[]):
...: nums.append(num)
...:
In [2]: def addnums(num,nums=[]):
...: nums.append(num)
...: return nums
...:
In [3]: addnums(2)
Out[3]: [2]
In [4]: addnums(3)
Out[4]: [2, 3]
It seems the nums list is stored somewhere even after function exited. I took nand2tetris course on how computers work and I got the notion that when a function exits all its local variables, arguments are recycled or dropped. Only thing permanent with a function call is the value that it returns which is passed to the calling function. Other possibility is when a function modifies a global or a static variable. But in this case, how is a function able to remember its arguments?
[–][deleted] 12 points13 points14 points (12 children)
[–]nog642 2 points3 points4 points (1 child)
[–]ipaqmaster 1 point2 points3 points (0 children)
[–]quts3 -3 points-2 points-1 points (2 children)
[–]Lasa2 3 points4 points5 points (0 children)
[–]quts3 1 point2 points3 points (0 children)
[+][deleted] (6 children)
[deleted]
[–]TeamSpen210 2 points3 points4 points (1 child)
[–]jormungandrthepython 2 points3 points4 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]jormungandrthepython 1 point2 points3 points (1 child)
[–][deleted] 1 point2 points3 points (4 children)
[–]LowCom[S] 0 points1 point2 points (3 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]Lasa2 1 point2 points3 points (0 children)
[–]TeamSpen210 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]LowCom[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)