I am confused by the scope of the names argument used in following example
def disp( p1, list=[] ):
list.append( p1 )
return list
list1 = disp( 10 )
list2 = disp( 123 )
list3 = disp( 'a' )
print ( list1 )
print ( list2 )
print ( list3 )
Output is
[10, 123, 'a']
[10, 123, 'a']
[10, 123, 'a']
How can we explain the scope of the variable list, which is the named argument in the function definition? Instead of a list, if it's something else, say integer, its works differently.
def disp2( p1, myVal = 0 ):
myVal += myVal + p1
return myVal
v1 = disp2(9)
v2 = disp2(7)
v3 = disp2(77)
print ( v1, v2, v3 )
Ideas? I want to understand the details behind the first example (its easy to avoid it, by changing the code ).