0
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;

  1. list1 : [1, 'a']
  2. list2 : [123]
  3. 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.

ThePyGuy
  • 17,779
  • 5
  • 18
  • 45
Sagar
  • 1
  • 3

0 Answers0