def push(stack:list):
stack = stack + [2]
stack = []
print(stack)
stack = stack + [1]
print(stack)
push(stack)
print(stack)
This is my python code.
I expected the final value of the list to be [1,2], but the result was [1]. I understand that the stack variable in the stack = stack + [2] code in push() is used as a local variable, but I don't know why. Also, I would like to know how to write the code, and how to add elements to a list without using append() inside a function that receives a list as a parameter.