Foundations · #1 of 11

Variables, Types, and I/O

Names, casting, and user input

Why it matters

Every bug you fix in Python starts with understanding types, names, and input/output.

The idea

Variables are labels stuck on objects. You can re-label anytime, but the object stays the same — and the object always carries its type.

Try it

type() is your fastest debugger. When numbers behave like strings (or vice versa), type() tells you why.

age = 25
height = 5.9
name = "Ada"
is_engineer = True
print(age, type(age).__name__)
print(height, type(height).__name__)
print(name, type(name).__name__)
print(is_engineer, type(is_engineer).__name__)
not loaded

input() ALWAYS returns a string. Cast before doing math — otherwise "2" + "3" == "23".

# input() blocked in Pyodide — pretend the user typed "42"
raw = "42"
print("raw:", raw, type(raw).__name__)
n = int(raw)
print("n*2 =", n * 2)

# What happens if you forget to cast?
try:
  print(raw + 1)
except TypeError as e:
  print("TypeError:", e)
not loaded

Quick check

Mini drills

Common mistakes

Key takeaways