'modifying a list in a function when passed to another function in Python [duplicate]

Look at the code below:

def f1(l):
  l[0] = 'row'
  l[1] = 'col'
  return True
def f2():
  l = [0,0]
  f1(l)
  print(l)
f2()

running the f2 function, prints l = ['row', 'col']. Why did this happen?

My Python version is 3.7.13



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source