LESSON 02 / 05

Variables & Types

Variables are named boxes. Meet Python’s basic types — int, float, str, bool — and learn to check and convert them.

🎓Beginnerlevel
⏱️30 minto finish
✏️2activities

📂 First Steps in Python🏷️ Variables

🎯 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)
TypeExamplesMeaning
int42, -7, 0whole numbers
float3.14, 2.0decimal numbers
str"hi", '42'text
boolTrue, Falseyes / no
NoneTypeNone“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 = 10 creates (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.