2.6 - Variable Re Assignment in Python
Summary
Highlights
Understanding Variable Reassignment00:00:00
Explains that when you reassign a variable in Python, such as changing 'myvar' from 10 to 15, you are not modifying the original object. Instead, Python creates an entirely new object in memory and updates the reference of the variable to point to that new address.
Evaluation During Reassignment00:01:16
Clarifies that expressions like 'myvar = myvar + 5' follow the same principle. Python evaluates the right-hand side first, creates a new integer object for the result, and points the variable reference to it, leaving the original object unchanged.
Demonstration with Memory Addresses00:02:20
Demonstrates through code that memory addresses change upon reassignment, proving that the underlying objects are distinct. It also introduces the concept of integer interning, where two variables assigned the same value may point to the same memory address.
Recently Summarized Articles
Related summaries
- Learn Pandas in 30 Minutes - Python Pandas Tutorial
- Flowchart tutorial
- What is Pseudocode in Python? Day 21
- If Else Statements in Python | Python for Beginners
- Compiler and Interpreter: Compiled Language vs Interpreted Programming Languages
- The Fetch-Execute Cycle: What's Your Computer Actually Doing?