r/pythonhelp • u/HeadTea • Jan 03 '23
Modifying an object through another function
I'm looking at this LeetCode solution and there's something I don't understand about it. The dfs function doesn't return anything. How does the matrix stay updated outside the dfs function if it doesn't return the newly modified list?
Thanks ahead!
0
Upvotes
3
u/carcigenicate Jan 03 '23 edited Jan 03 '23
Note the line:
That's a mutative operation, so
dfsis a mutative function. It alters the object given to it.This is a simpler example of the same idea:
appendmodifies the object passed to the function.