0

Here is a little problem with a function that takes a parameter and print the parameter. Parameter is a list in this case. Because this is just a test for a bigger project I want to copy the list in a variable data and modify first element. Why also param's first element is modified and how to change to keep it the same after the modification of data[0] ?

def function(param):
    data = param
    data[0] = 45
    print(param)

if __name__ == "__main__":
    param = [12, 4, 64]
    function(param)
Mihai
  • 11
  • 1
  • Python lists are passed by reference, not by argument. That's a pretty frequent question. If you want to make a copy, use a slice. – imperosol Apr 01 '22 at 16:59

0 Answers0