Lesson 145 of 1570
Python Variables & Types — With an AI Explainer Beside You
Variables are named boxes for data. You'll write your first ten, then use AI to decode error messages and grow your intuition for types.
Lesson map
What this lesson covers
Learning path
The main moves in order
- 1A variable is a name with a value
- 2variables
- 3types
- 4int
Concept cluster
Terms to connect while reading
Section 1
A variable is a name with a value
In Python, you create a variable by typing a name, an equals sign, and a value. Python figures out the type automatically. That is both its magic and its trap — the moment you mix types wrong, it yells.
Run this in any Python 3.12+ file. The f-string in the print statement embeds variables directly.
# The four types you will use every day
name = "Maya" # str (text)
age = 13 # int (whole number)
height_m = 1.58 # float (decimal)
is_student = True # bool (True or False)
print(f"{name} is {age} years old.")
print(f"Type of age: {type(age).__name__}")Typecasting: turning one type into another
input() returns a string. You must cast it before doing math.
user_input = input("Your age? ") # input() always returns str
age = int(user_input) # cast to int for math
next_year = age + 1
print(f"Next year you'll be {next_year}.")
# The classic bug: forgetting to cast
bad = user_input + 1 # TypeError: can only concatenate str (not "int") to strMini-exercise
- 1Create variables for: your first name, your age, your favorite decimal number, and whether you like pineapple on pizza
- 2Print a sentence using an f-string that uses all four
- 3Deliberately cause a TypeError by adding a str to an int
- 4Paste the error into your AI assistant and ask it to explain
Compare the options
| Python | TypeScript | What's similar |
|---|---|---|
| name = "Maya" | const name = "Maya"; | Name = value |
| age = 13 | const age: number = 13; | TS asks for the type explicitly |
| is dynamic (type inferred) | is static (type checked) | Python finds bugs at runtime; TS finds them before you run |
Big idea: Python infers types so you write less, but mistyped values still blow up. Pair every new variable with a quick 'what type is this?' check in your head — and if you cannot tell, ask your AI.
End-of-lesson quiz
Check what stuck
15 questions · Score saves to your progress.
Tutor
Curious about “Python Variables & Types — With an AI Explainer Beside You”?
Ask anything about this lesson. I’ll answer using just what you’re reading — short, friendly, grounded.
Progress saved locally in this browser. Sign in to sync across devices.
Related lessons
Keep going
Builders · 30 min
Python Basics With an AI Pair
Variables, loops, and functions are the atoms of Python. Let an AI help you write them while you learn what each line actually does.
Builders · 35 min
TypeScript Fundamentals With AI
TypeScript is JavaScript with types. Learn how `strict` mode catches bugs at compile time and how AI writes cleaner types than you might alone.
Builders · 25 min
What Does AI-Assisted Coding Even Mean?
AI-assisted coding is not magic and not cheating. It is a new way of working where a model drafts, you decide. Let's draw a map before we start building.
