Skip to main content

Command Palette

Search for a command to run...

I finally figured out what happens to previous data when a variable changes value

Published
1 min read
I finally figured out what happens to previous data when a variable changes value
X

"I am currently a Software Engineering student at ALX. I'm passionate about technology and enjoy conducting research to find answers on my own. I have a natural inclination to ask 'WHY' more often than 'HOW'.

"While working on projects at ALX, I have acquired a wealth of interesting and diverse knowledge about software engineering and computer science in general. Therefore, I needed a place to store and save all this information, allowing me to refer back to it whenever I forget."

whenever you reassign a variable, the old value doesn't get erased by the new one; the variable simply switches to refer to the new value. The effect is like moving a sticky note from one object to another.
a = 10 a = 12
when you do something like this, 10 is not deleted or removed, it will still be there somewhere in your computer memory, another memory is been created for 12 and a is now made to point to this new value(yea python relates with c)

By the way, even though the assignment statement doesn't directly cause the old value of a variable to be erased and overwritten, you don't have to worry about computer memory getting filled up with the "discarded" values.

When a value is no longer referred to by any variable, it is no longer useful. Python will automatically clear these values out of memory so that the space can be used for new values.

In fact, this process of automatic memory management is actually called garbage collection.

More from this blog

PERSONAL BLOG

110 posts

Use the search button to search for a specific topic or keyword *all posts are updated on the go*