Variables & Types
Think of a variable as a labeled box. You don't need to tell the box in advance whether it will hold a number, a word, or a list — you just put something in it, and Python figures out what kind of thing it's holding by looking at it. That's the essence of dynamic typing: the type lives with the value, not with a permanent declaration on the box itself.
age = 30
name = "Ada"
is_registered = True
No int, no string, no type keyword anywhere. Python looks at
30 and knows it's an integer. It looks at "Ada" and knows it's text. You
just assign, and the label — the variable name — now points at that value.
💡 The Bottom Line
In Python, variables don't have a fixed type — values do. The same variable name can point at an integer one moment and a string the next, because assignment just re-points the label. This is called dynamic typing, and it's a huge part of why Python code reads so cleanly.
The core types you'll use constantly
Almost everything you write in early Python leans on a small handful of built-in types:
int
Whole numbers: 7, -3, 1000. No size limit worth
worrying about as a beginner.
float
Numbers with a decimal point: 3.14, -0.5. Used whenever whole
numbers aren't precise enough.
str
Text, wrapped in quotes: "hello" or 'hello' — Python treats single
and double quotes the same.
bool
Exactly two values: True or False (note the capital letters — this
trips people up).
There's also a special value, None, which means "no value at all" — Python's way of
saying a variable intentionally holds nothing yet.
You never have to guess what type a value is — just ask:
>>> type(age)
<class 'int'>
>>> type(name)
<class 'str'>
>>> type(is_registered)
<class 'bool'>
🙋 There Are No Dumb Questions
Q: If types aren't declared, does that mean Python doesn't care about types at all?
A: It cares a lot — it just checks at a different time. Python is dynamically typed (types are
checked while the program runs, not before) but it's still strongly typed: it will never
silently treat "5" (text) as the number 5 for you. Try
"5" + 3 and Python raises a TypeError rather than guess what you meant.
Converting between types
Since Python won't silently mix types, you convert explicitly when you need to, using the type names themselves as functions:
age_text = "30"
age_number = int(age_text) # "30" -> 30
price = str(19.99) # 19.99 -> "19.99"
count = float("2.5") # "2.5" -> 2.5
This comes up constantly in real programs — user input, data read from a file, or a value pulled from a website all arrive as text, and you convert it to a number the moment you need to do math with it.
⚠️ Watch Out
A very common early bug: reading a number as text and trying to do arithmetic on it directly.
input(), for example, always returns a string, even if the person typed
"42". Forgetting to wrap it in int() before doing math is one of the
most common first bugs in any beginner's first Python script.
🔧 Try It Yourself
In the REPL or a script, create three variables: your age as an int, your height
in meters as a float, and your name as a str. Then print a sentence that
combines all three, converting the numbers to strings first:
age = 29
height = 1.75
name = "Sam"
print(name + " is " + str(age) + " years old and " + str(height) + "m tall.")
Try removing one of the str() calls and running it again — you should see a
TypeError, proof that Python really won't mix text and numbers without being asked.
✅ Quick Check
What happens if you assign a string to a variable that previously held an integer, like
x = 5 followed by x = "five"?
Next up: single values only get you so far. Lesson 4 covers Python's real workhorses — lists, dictionaries, and tuples — the data structures behind almost every useful program.