Python Basics for Vibe Coders, Part 2: Variables and What = Really Means
Python variables are name tags, and = doesn't mean "equals." Numbers, strings, booleans, f-strings, why "20" + "1" is 201, and reading AI code.
Open any Python code an AI wrote for you and you'll find = on almost every line: name = "Mia", total = total + price, and so on. If you read that = as "equals" like in math, the code looks strange and the flow of AI code gets hard to follow. This is Part 2 of the 10-part series "Python Basics for Vibe Coders." It covers variables and the basic data types: numbers, strings, and booleans (true/false). The examples are written for Python 3.15, and I ran them in Python 3.14.2 to check the results.
Key Takeaways
- A variable is less a box that holds a value and more a name tag stuck on a value.
=doesn't mean "equals." It means "calculate the value on the right, then attach the name on the left to it."- The same
20is a string with quotes and a number without them."20" + "1"becomes"201".- When you're not sure what kind of value something is, check with
type().
Why variables matter for vibe coders
Reading AI code mostly means tracking "what value is attached to this name right now?" Just reading variable names well tells you a lot about what the code does. On the flip side, when a variable name the AI picked doesn't match the actual value (say, count holds text), that's a likely spot for a bug.
Think of your contacts app. Instead of memorizing a phone number, you save it under a name like "Mom." If the number changes, you keep the name and update the number. Variables work the same way. You give a value a name, and when needed, you change the value that name points to.
Creating variables and kinds of values
name = "Mia"
age = 20
height = 1.65
is_student = True
print(name, age, height, is_student)
print(type(age), type(height))
print(f"Name: {name}, Age: {age}")
age = age + 1
print(age)
Mia 20 1.65 True
<class 'int'> <class 'float'>
Name: Mia, Age: 20
21
Here's what each value is:
| Code | Kind of value | Meaning |
|---|---|---|
"Mia" | String (str) | Text wrapped in quotes |
20 | Integer (int) | A number with no decimal point |
1.65 | Float (float) | A number with a decimal point |
True | Boolean (bool) | Only two values: True or False |
f"..." is an f-string. Put an f before a string and a variable name inside curly braces {}, and the value fills that spot. AI code uses this constantly to build messages.
= doesn't mean "equals," it means "attach a name"
Read as math, age = age + 1 makes no sense. No number can equal itself plus 1. Here's how Python actually runs that line:
- It calculates the right side,
age + 1, first.ageis currently 20, so the result is 21. - It moves the
agename tag onto that new value, 21. (Programmers call this assignment: you assign a value to a name.)
So if you run x = 5 and then x = x + 2, x is 7. In AI code, total = total + price reads as "add the price to the running total and update the total."
The name tag analogy also covers things a box analogy struggles to explain. You can stick several name tags on the same value, and you can peel a tag off and move it to a different value. The moment you run age = 21, the name age comes off 20 and moves to 21.
Common trap: is a number in quotes still a number?
They both look like 20 to you, but to Python they're different values.
print("20" + "1")
print(20 + 1)
201
21
For strings, + joins them. For numbers, + adds them. Mix a string and a number, like "20" + 1, and you get a TypeError. Vibe coders run into this all the time. input(), which reads keyboard input, always returns a string even if you type a number, and values read from files (Part 9) or the web are often strings too. If you see int(...) or float(...) in AI code, it's usually converting a string into a number.
price = "1500"
print(int(price) * 2)
3000
If a result comes out oddly glued together (for example, a total of 15001500), use type() to check whether you added two strings.
What to check when reading AI code
- Does each variable name match its actual value? Be suspicious if
priceholds text oris_doneholds a number. - Are the values used in calculations actually numbers? If they came from input or a file, look for an
int()orfloat()conversion. - Is there a line partway through that reassigns the same name (
x = ...)? If so, read everything below it with the new value.
When you ask the AI for a fix, saying which variable's value is wrong and how gets you a much more accurate answer. For example: "The total comes out as 15001500. I think price is a string."
Check yourself
- After
x = 5, you runx = x + 2. What isx? → 7. Python calculates the right side first (7), then attachesxto it. If you picked "it causes an error," you read=as an equation. - What does
print("3" + "4")print? → 34. Values in quotes are strings, so they get joined.
Try it yourself
Create three variables for a name, an age, and a favorite food, and print one sentence with an f-string. If the sentence changes when you change the variable values, you did it. If you get stuck, check the f before the string and the curly braces {}.
name = "Sam"
age = 25
food = "pizza"
print(f"{name} ({age}) likes {food}.")
Sam (25) likes pizza.
Previous and next
- Previous: Part 1: Where Do You Run the Code AI Gives You?
- Next: Part 3: Conditionals covers
if / elif / else, which compares values to pick a path, and the condition-order bug that's easy to miss in AI code.
The full series list is at the end of Part 10.