def push(item,stack=[]):
#print('stack',stack)
stack.append(item)
return stack
if __name__== '__main__':
print(push(5))
print(push(6))
print(push(7))
stck = push(58)
print(stck.pop())
print(stck.pop())
print(push(9))
Answer:
[5]
[5, 6]
[5, 6, 7]
58
7
[5, 6, 9]
How the second push(6) is maintaining the stack array isnt the second push() method supposed to create a new array, and how its maintaining the array between the multiple method calls of push()