python / python-basics
12 mins
Python Level 1: Variables, F-Strings & Input
Why This Matters: Python F-strings provide fast, readable string interpolation.
## Variables & F-String Interpolation
Python features built-in types: `int`, `float`, `str`, and `bool`.
```python
age = 21
gpa = 3.88
name = "Alex"
print(f"{name} is {age} years old with a {gpa} GPA.")
```
MENTAL MODEL & MEMORY LAYOUT
F-String Evaluation:
f"{name} is {age}" ──► Evaluates expressions inside {} ──► "Alex is 21" COMMON PITFALLS TO AVOID
- Trying to concatenate str and int with `+` without calling `str(val)` or using f-strings.
F-String Interpolation Pattern
x = 10
y = 20
print(f"Product of {x} and {y} is {x * y}")Evaluates mathematical expressions inside f-string curly braces at runtime.
CONCEPT MASTERY CHECKPOINT
Which string formatting syntax is recommended in modern Python 3?
NEXT RECOMMENDED LESSON
Python Level 2: Control Flow & Loops
Challenge: Write a function `calculate_area(width, height)` that returns the area of a rectangle.