8 min read Beginner Lesson 1 of 11
Part 1 — Thinking Like a Programmer

Variables & Memory

Variables are not mere names on a screen. In Python, variables are named references pointing to dynamically allocated objects living in RAM.

Python Variables Are Name Tags, Not Fixed Boxes

In languages like C, a variable is a physical box of fixed size in memory. In Python, every value (integers, strings, floats) is a rich heap object, and your variable is simply a Name Tag pointing to that object's memory address!

How Python Variables Point to Objects

Code Statement Variable (Name Tag) Heap Memory Address Object Value & Type
score = 100 score 0x7ffd10a4 100 <int>
name = "Ada" name 0x7ffd10e8 "Ada" <str>
high_score = score high_score 0x7ffd10a4 Points to same 100 object!

Both score and high_score point to the identical integer object in RAM.

Python's 4 Core Primitive Types

int

Integers

42, -7, 1000
float

Decimals

3.14159, -0.5
str

Strings

"Hello, World!"
bool

Booleans

True, False

Quick Summary

  • Variables are named references pointing to typed heap objects in memory.
  • Next, we explore Conditions & Logic to make code make intelligent decisions.