Python You Won't Find in TypeScript
Python-only territory
Section titled “Python-only territory”TypeScript is a superset of JavaScript — it adds types, but the runtime is still JS. Python, by contrast, was designed from scratch with a different philosophy: code should read like executable pseudocode. The result is a language with several concepts that simply have no equivalent in TypeScript or JavaScript.
This module walks through ten of those concepts:
- Significant whitespace — indentation is syntax, not style.
- Duck typing and EAFP — structural behavior without interfaces, plus try-first error handling.
- Dunder methods — operator overloading via
__add__,__str__, and friends. - Decorators — first-class function wrappers, used heavily in frameworks like FastAPI.
- Comprehensions — concise list, dict, and set construction.
- Generators and
yield— lazy sequences that produce values on demand. - Unpacking,
*args,**kwargs— flexible function signatures and iterable destructuring. - Context managers —
withblocks that guarantee resource cleanup. - Slicing — powerful subsequence syntax for lists, strings, and more.
- The GIL — the Global Interpreter Lock and what it means for concurrency.
The feel: braces vs whitespace
Section titled “The feel: braces vs whitespace”The most immediately visible difference between TypeScript and Python is syntax. TypeScript inherits JavaScript’s C-style braces and semicolons. Python uses neither.
// TypeScript: braces and semicolons everywherefunction greet(name: string): string { if (name) { return `Hello, ${name}!`; } else { return "Hello, stranger!"; }}
const items: number[] = [1, 2, 3];for (const item of items) { console.log(item);}# Python: indentation defines blocksdef greet(name: str) -> str: if name: return f"Hello, {name}!" else: return "Hello, stranger!"
items: list[int] = [1, 2, 3]for item in items: print(item)Try it
Section titled “Try it”# A taste of Python's feeldef describe(value): if isinstance(value, int): print(f"{value} is an integer") elif isinstance(value, str): print(f'"{value}" is a string') elif isinstance(value, list): print(f"{value} is a list with {len(value)} items") else: print(f"{value} is something else")
describe(42)describe("hello")describe([1, 2, 3])describe(3.14)
# Python reads like prosenumbers = [1, 2, 3, 4, 5]evens = [n for n in numbers if n % 2 == 0]print(f"Even numbers: {evens}")Loading Python runtime (first run only)…