I am new in python, so I do not understand function well
def extendList(val,list=[]):
list.append(val)
return list
list1 = extendList(10)
list2 = extendList(123,["a","b","c"])
list3 = extendList('a')
print "list1 = %s"% list1
print "list2 = %s" % list2
print "list3 = %s" % list3
The result I expected is
list1 = [10]
list2 = ['a', 'b', 'c', 123]
list3 = ['a']
However,the actual result is
list1 = [10, 'a']
list2 = ['a', 'b', 'c', 123]
list3 = [10, 'a']
Why is it happening ?