Python15 min read
Python Variables
Learn how variables work in Python, how to name them correctly, and how assignment behaves.
Emily Davis
September 16, 2025
5.0k216
Variables are how programs store information. A variable is a name that points to a value in memory.
The key idea:
- You create a variable by assigning a value to it with
=
Create variables
name = "John"
age = 25
city = "New York"
is_student = True
print(name)
print(age)
print(city)
print(is_student)
Expected output:
John
25
New York
True
What assignment really means
In Python, = means “make this name refer to this value”.
a = 10
b = a
a = 20
print(a)
print(b)
Expected output:
20
10
This shows that b kept the old value. Python does not “link” them in this simple example.
Naming rules (do this from day 1)
Good names tell the reader what the data represents.
✅ Good:
total_price = 120.50
user_email = "john@example.com"
items_in_cart = 3
❌ Poor:
x = 120.50
temp = "john@example.com"
n = 3
Python naming style
Python developers mostly use snake_case:
user_nametotal_costis_active
Updating variables
score = 0
print(score)
score = 10
print(score)
score = score + 5
print(score)
Expected output:
0
10
15
Graph: name to value
flowchart LR
A[name] --> B["John"]
C[age] --> D[25]
E[score] --> F[15]
One concept that prevents bugs
If you see wrong output, check:
- What value is stored?
- Where did it change?
- What line updated it?
That thinking makes debugging easier.
In the next lesson, you will learn data types so you understand what kind of values Python variables can hold.
#Python#Beginner#Variables