0

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

3
  • 1
    What do you think should have happened instead, and why? Commented Apr 12, 2022 at 23:47
  • Because you mutated the dict. What else did you expect to happen? Commented Apr 13, 2022 at 0:11
  • @ScottHunter @juanpa.arrivillaga I gueseed l = [0,0] because I didn't return the list from f1. I think that l could be ['row', 'col'] in 2 situations: 1) When I've defined l globally and 2) when f1 returns a list and in f2, I have this line: l = f1(l) Commented Apr 14, 2022 at 12:43

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.