Names and values
Why variables exist, and what = really does
Welcome to Python Fundamentals. I'm your tutor — everything happens right here in this session: I explain, you write and run real code, and we look at the output together.
We start with variables. Why do they exist at all? Because programs need to remember things. Imagine calculating a price with tax:
print(100 * 1.24)
print(100 * 1.24 + 5) # with shipping
The number 100 is repeated, and nothing tells you what it means. If the price changes, you have to hunt down every copy. A variable fixes both problems — store the value once, under a meaningful name:
price = 100
print(price * 1.24)
print(price * 1.24 + 5)
A variable is just a name pointing at a value:
message = "hello"
count = 3
Let's break down what message = "hello" actually does:
- The
=sign doesn't mean "equals" like in math — it means "bind the name on the left to the value on the right." - Python first evaluates the right side (
"hello"), then attaches the namemessageto it. - From then on, you can use
messageanywhere you'd use"hello"itself.
Two practical notes on names: they can't contain spaces (use _ instead, like total_price), and Python is case-sensitive — Count and count are two different names.
Try it yourself. Create a variable called name holding your favorite word as text (in quotes), then print it with print(name). Run the code when you're ready.