Variables and Types
In Python, a variable is a name that points to a value. You don't declare a type up front the way some languages require — Python figures the type out automatically from the value itself, the moment you assign it.
name = "Ada" # str (text)
age = 28 # int (whole number)
height = 1.65 # float (decimal number)
is_learning = True # bool (True or False)
Checking a variable's type for real
You don't have to guess — Python's built-in type() function tells you exactly what type a value actually is:
Run it, then change one of the values above (try age = 28.0 instead of 28) and run it again — notice the type genuinely changes with the value, not with how the variable was originally used.
Naming rules and real conventions
A variable name must start with a letter or underscore, can contain letters/numbers/underscores after that, and cannot be a reserved Python keyword (like True, if, or for). Beyond what's technically required, real Python code follows a genuine convention: snake_case — lowercase words separated by underscores, like total_score or first_name, not totalScore or TotalScore (those styles belong to other languages, and to Python classes specifically, which you'll meet in Week 7). Following this convention isn't optional in any real professional codebase — code that doesn't follow it genuinely reads as "written by someone new to Python," even if it works correctly.
Reassignment: a variable can point to something new
score = 10
print(score) # 10
score = 20 # NOT the same as creating a new variable — this REPLACES what score points to
print(score) # 20
score = "high" # completely legal — Python doesn't lock a variable to its first type
print(score) # high
That last line is a real, deliberate feature of Python called dynamic typing — a variable name is just a label you can point at any value, of any type, at any time. This is genuinely different from some other languages (like Java or C), which permanently lock a variable to one type the moment it's declared. Dynamic typing is part of why Python code reads so cleanly, though it does mean you are responsible for keeping track of what a variable actually holds, since Python won't stop you from changing it.
Multiple assignment in one line
x, y, z = 1, 2, 3
print(x, y, z) # 1 2 3
A genuinely common, idiomatic pattern — assigning several related variables in one clean line instead of three separate ones.
This week's practical exercise
Use the runnable box above to declare a variable for each of the four types shown (a string, an int, a float, a bool), print each one's type(), then change your string variable to a number and print its type again to see it genuinely change. When you're ready, the graded assignment below builds directly on this.
Further reading
- Python's official "Numbers" section — direct from Python's own tutorial
- Real Python: Basic Data Types in Python — a deeper, well-regarded independent walkthrough of the same ideas
Try it
Use the editor on the right to complete the assignment below. Ask your tutor if anything is unclear — they can see your code as you type.
Build a Summary String
Write code that creates four variables:
name— your name, as a stringage— your age, as an integerheight_m— your height in meters, as a floatis_learning— alwaysTrue
Then build a single string called summary in this exact format (no extra words):
{name} is {age} years old, {height_m}m tall, and learning to code: {is_learning}
Print summary on its own line.