Ask Your Question
3

The state of a Python object variable seems to persist even when reassigned to a different object.

asked 2022-04-27 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-10-06 14:00:00 +0000

pufferfish gravatar image

This is because when an object is assigned to a variable in Python, the variable simply points to the memory location where the object is stored. When the variable is reassigned to a different object, it simply points to a new memory location. The original object is still stored in memory and can be accessed through its original reference, if it has not been garbage collected. Therefore, any changes made to the original object will still be reflected, even if the variable that initially pointed to it has been reassigned.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-04-27 11:00:00 +0000

Seen: 8 times

Last updated: Oct 06 '21