Skip to content

Python 101 — Fundamentals

If you have shipped TypeScript, you already know more Python than you think. Both languages are dynamically typed at their core (TypeScript adds a compile-time type layer; Python 3 adds optional hints), both are garbage-collected, and both lean on expressive syntax over ceremony. The biggest mental shift is cosmetic: indentation replaces curly braces, and a lot of JavaScript’s syntactic sugar has a cleaner Python equivalent.

This module walks you through nine lessons, each anchored in code you already know. You will leave with enough Python to read real projects, write scripts, and build REST APIs with FastAPI.

A quick taste: the same program in both languages

Section titled “A quick taste: the same program in both languages”

Here is a tiny program — a list of names filtered and greeted — written first in TypeScript, then in Python. Same logic, same output, different syntax.

TypeScript
const names: string[] = ["Alice", "Bob", "Carol", "Dave"];
const short = names.filter((n) => n.length <= 4);
for (const name of short) {
console.log(`Hello, ${name}!`);
}
// Hello, Bob!
// Hello, Dave!
Python
names: list[str] = ["Alice", "Bob", "Carol", "Dave"]
short = [n for n in names if len(n) <= 4]
for name in short:
print(f"Hello, {name}!")
# Hello, Bob!
# Hello, Dave!
names: list[str] = ["Alice", "Bob", "Carol", "Dave"]
short = [n for n in names if len(n) <= 4]
for name in short:
print(f"Hello, {name}!")
LessonYou already know (TS)You will learn (Python)
Variableslet / const + static typesDynamic typing, type hints, UPPER_CASE constants
FunctionsArrow & functiondef, default args, keyword args, *args/**kwargs
Control Flowif/else, for, switchif/elif, for...in, match/case
CollectionsArray, object, Map, Setlist, tuple, dict, set, slicing
Classesclass, constructor, thisclass, __init__, self, dunders
ModulesESM import/export, npmimport, from ... import, pip
Errorstry/catch/finallytry/except/else/finally, raise
None & Truthinessnull, undefined, falsy valuesNone, is None, Python truthiness
What replaces curly braces to define code blocks in Python?
Python type hints (e.g. `name: str`) are enforced at:
Which Python construct is the closest equivalent of a TypeScript `Array.filter()` one-liner?