Skip to content
Streak:0Loading your progress…Sign in

Module 1 · Lesson 1 of 3

Variables, types and f-strings

No var, no let, no semicolons. Dynamic typing with optional type hints. ~15 min

Lesson notes

Python is dynamically typed: a name points at an object, and the object carries the type. You don't declare variables — you just assign. Blocks are defined by indentation (4 spaces by convention), not braces.

Coming from Dart

Dart

final name = 'Ada';
var age = 36;
print('$name is $age');

Python

name = "Ada"
age = 36
print(f"{name} is {age}")

f-strings are Python's string interpolation. Anything inside {} is an expression: f"{age * 2}" works.

Core types: int (arbitrary precision — no overflow!), float, bool (True/False, capitalised), str, and None (Python's null). Use type(x) to inspect and isinstance(x, int) to check.

Integer vs float division
7 / 2    # 3.5  -> always a float
7 // 2   # 3    -> floor division
7 % 2    # 1    -> remainder
2 ** 10  # 1024 -> exponent

Practice

  1. 1. Format a greeting

    easy10 XP

    Write greet(name, score) that returns the string "Hi <name>, you scored <score>%" where score is shown with exactly one decimal place. Example: greet("Ada", 92.456) → "Hi Ada, you scored 92.5%".

    Ctrl/⌘ + Enter runs the tests · Esc then Tab leaves the editor

  2. 2. Truthiness check

    Quizeasy5 XP
    Which of these values is truthy in Python?