When you assign a list of one variable to another variable, both belong to the same list.
spy = [0,0,7]
agent = spy
spy[2]=8
so you change the spy, so the agent also changes because both belong to the same list in the same memory location. You can check that
id(spy)
id(agent)
which cause a call by reference.
But if you assign a new list to the spy after initializing the agent, then the spy belongs to another list in a different memory location.
id(spy)
id(agent)
You can also check this with the id () function, which provides a reference identifier for a variable in memory.
source
share