0
def myFunction(x,myList=[]):
    for i in range(x):
        myList.append(i*i)
    print myList

myFunction(2)
myFunction(3,[3,2,1])
myFunction(3)

Output is:
[0, 1]
[3, 2, 1, 0, 1, 4]
[0, 1, 0, 1, 4]

Can someone help, instead of print [0,1,4] for third called function, the output is [0,1,0,1,4] as value get append to the output of first called function. What is the logic behind it.?

user341143
  • 448
  • 4
  • 12

0 Answers0