The Quiet Terminal

← Beginner

Variables, strings, numbers, and booleans

2026-03-27 · 3 min read

For my first few weeks of Python, every variable I made was a string, because everything I typed went inside quotes. Then I tried to do math on one and met my first TypeError. This post is the ground floor I wish I'd had that afternoon: the four types that carry almost every beginner script, how to ask Python what a name is holding, and the one crash everybody meets exactly once.

Names are labels, not boxes

In a lot of languages a variable is a box: you build it a certain size and a value lives inside. Python isn't like that. A name is a label, and assignment just sticks the label onto a value:

age = 26
year = 2026 - age    # the label 'age' leads Python back to the 26

This turns practical the moment anything changeable shows up: two labels can be stuck on the same list, and a change made through one shows through the other. Numbers and strings hide all of that, but the label picture is the honest one, and it will save you an afternoon somewhere down the line. Rebinding is the other half of the idea — age = 27 doesn't reach back and change anything old, it just moves the sticker.

Four types carry most scripts

Unsure what a name is holding? Just ask:

name = "Maya"        # str   — text, in quotes
age = 26             # int   — whole numbers
height = 1.68        # float — decimal numbers
is_admin = False     # bool  — True or False, no quotes

type(age)          # <class 'int'>
type(height)       # <class 'float'>
type(name)         # <class 'str'>
type(is_admin)     # <class 'bool'>

Two number details worth learning early. First, / always produces a float, even when the answer is whole — and the day that matters is the day a divided value ends up between list brackets, because indexes must be whole numbers:

10 / 2        # 5.0  — a float, not the int 5
10 // 2       # 5    — floor division keeps the int
0.1 + 0.2     # 0.30000000000000004 — floats are approximations
2 ** 100      # 1267650600228229401496703205376 — ints just grow

Booleans are answers to questions

A bool is what comes back when you ask a question with a comparison:

age >= 18         # True
name == "maya"    # False — capital M matters
height != 1.75    # True

Two equals signs ask "are these equal?"; a single one assigns. I stopped mistyping it once I started reading x == 5 out loud as "is x equal to 5?". Booleans sit quietly in variables until an if statement needs them — which is where they do their real work.

The crash everybody meets once

age = "26"            # the quotes snuck in
print(age + 1)
# TypeError: can only concatenate str (not "int") to str

int("26") + 1         # 27 — convert at the boundary
str(26) + "!"         # 26!

Python refuses to add a string to a number, and it won't even guess whether you wanted 27 or "261". When that red wall hit me the first time, I did what everyone does: changed random things until it went away. The better habit is reading the last line of the error, which had named the problem all along — str and int can't be added. That habit now has its own post: reading a traceback from the bottom up.

One habit change did more for me than everything above: I stopped naming things x and d and started naming them age_years and price_eur. When the name says what the value is, the type usually announces itself, and type() becomes a flashlight for the occasional debug instead of a crutch on every line.