AtomLearn
DashboardGoalsGraphAchievementsReviewSign In
DashboardProgramming FundamentalsVariables & Assignment
Programming FundamentalsNot Started

Variables & Assignment

How to store and name data in memory

0%

Explanation

A variable is a named label that points to a value stored in memory. When you write x = 5, Python reserves a spot in memory, stores the integer 5 there, and gives you the label x to refer to it.

A variable is a label pointing to a value in memoryx = 5xlabel5int · memory address 0x…10after x = 10reassignx points to a new value on reassignment — the old value (5) is garbage collected if nothing else references it

Key ideas

  • A variable stores a value — you read it by name, change it by reassigning
  • x = 10 doesn't modify the old value — it makes x point to a new one
  • Python figures out the type from the value — no int x declarations needed
  • Multiple variables can point to the same value: a = b = 5

Naming rules

  • Must start with a letter or underscore: name, _count, x1
  • Cannot start with a digit: 2fast
  • Can contain letters, digits, and underscores only — no hyphens or spaces
  • Case-sensitive: score, Score, and SCORE are three different variables
  • Cannot use reserved keywords: if, for, while, class, return

Convention: use snake_case

python
user_name = "Alice"    # ✓ Python convention
userName  = "Alice"    # ✗ camelCase (works but not Pythonic)

Examples

Basic assignment

Assign different types of values to variables

x = 5
name = "Alice"
is_active = True
print(x, name, is_active)  # 5 Alice True

Reassignment

A variable can be reassigned any number of times

score = 0
print(score)  # 0
score = score + 10
print(score)  # 10

Next in Programming Fundamentals

Data Types

Continue