🎯 By the end of this lesson you can…
- Create and update variables
- Recognise int, float, str and bool
- Convert between types
Boxes with names
🐍 Python
variables.py
👆 Tap a line to explain it
1name = "Asha"2age = 143height = 1.524is_student = True5print(name, age, height, is_student)6age = age + 17print(name, "is now", age)
| Type | Examples | Meaning |
|---|---|---|
int | 42, -7, 0 | whole numbers |
float | 3.14, 2.0 | decimal numbers |
str | "hi", '42' | text |
bool | True, False | yes / no |
NoneType | None | “nothing here yet” |
🐍 Python
types.py
👆 Tap a line to explain it
1print(type(42), type(4.2), type("42"), type(True))2print(int("42") + 1)3print(str(42) + "!")4print(float("2.5") * 2)5print(int(3.99))
Naming rules
- letters, digits and
_only; can’t start with a digit - case-sensitive:
score≠Score - Python style is snake_case:
total_score,first_name
🔮 What will this display?
What does this print?
1x = 52y = x3x = x * 24print(x, y)
🛠️ Swap values
Swap the values of a and b and print them. (Python has a one-line swap: a, b = b, a.)
📌 Key takeaways
score = 10creates (or updates) a variable — no special keyword needed.type(x)shows the type;int(),float(),str()convert.- Names use snake_case:
total_score.
Finished reading & practising?
Saved in this browser. Create a free account to keep it forever.