def addtoList(val,list=[]):
list.append(val)
return list
list1 = addtoList(1)
list2 = addtoList(123,[])
list3 = addtoList('a')
print ("list1 = %s " %list1)
print ("list2 = %s " %list2)
print ("list2 = %s " %list3)
The above script will produce the answer;
- list1 : [1, 'a']
- list2 : [123]
- list3 : [1, 'a']
I can understand the element will be added to same list as it is appended.
I need to comprehend two things, why list2 is not comprise [1] and empty list.