Basics & Syntax
Python’s design philosophy
Section titled “Python’s design philosophy”Python was designed around a single guiding principle: code should read like plain English. Guido van Rossum, Python’s creator, made explicit trade-offs in favour of readability — even when that meant restricting programmer freedom.
The philosophy is captured in PEP 20, known as The Zen of Python.
Run import this in any Python session to see it.
Three lines that shape everything:
- Beautiful is better than ugly.
- Explicit is better than implicit.
- There should be one — and preferably only one — obvious way to do it.
That last point matters most for learning: when you look up how to do something in Python, there is almost always a canonical answer.
Significant whitespace
Section titled “Significant whitespace”Python uses indentation (4 spaces per level, by convention) to define blocks. There are no curly braces and no semicolons.
def is_even(n: int) -> bool: if n % 2 == 0: return True return False
for i in range(5): if is_even(i): print(i, "is even")Mixing tabs and spaces causes a TabError.
The community standard (PEP 8) is 4 spaces — configure your editor once and forget about it.
What this module covers
Section titled “What this module covers”| Lesson | Core concept |
|---|---|
| Variables & Types | Dynamic typing, built-in types, truthiness |
| Control Flow | if/elif/else, for, while, walrus := |
| Functions | def, parameters, return values, LEGB scope |
| Strings | Methods, slicing, f-strings, immutability |
Each lesson is self-contained and ends with a runnable playground, a callout, a quiz, and a progress checkpoint.
Your first Python script
Section titled “Your first Python script”The script below demonstrates the core syntax you will encounter in every lesson: variables, a function, a loop, and an f-string.
def describe(value: int) -> str: """Return a short description of a number.""" if value < 0: label = "negative" elif value == 0: label = "zero" else: label = "positive" return f"{value} is {label}"
numbers = [-3, 0, 7, 42]for n in numbers: print(describe(n))
total = sum(numbers)print(f"Sum: {total}")print("First program complete.")Loading Python runtime (first run only)…