Skip to content

Python You Won't Find in TypeScript

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:

  1. Significant whitespace — indentation is syntax, not style.
  2. Duck typing and EAFP — structural behavior without interfaces, plus try-first error handling.
  3. Dunder methods — operator overloading via __add__, __str__, and friends.
  4. Decorators — first-class function wrappers, used heavily in frameworks like FastAPI.
  5. Comprehensions — concise list, dict, and set construction.
  6. Generators and yield — lazy sequences that produce values on demand.
  7. Unpacking, *args, **kwargs — flexible function signatures and iterable destructuring.
  8. Context managerswith blocks that guarantee resource cleanup.
  9. Slicing — powerful subsequence syntax for lists, strings, and more.
  10. The GIL — the Global Interpreter Lock and what it means for concurrency.

The most immediately visible difference between TypeScript and Python is syntax. TypeScript inherits JavaScript’s C-style braces and semicolons. Python uses neither.

TypeScript
// TypeScript: braces and semicolons everywhere
function 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
# Python: indentation defines blocks
def 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)
# A taste of Python's feel
def 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 prose
numbers = [1, 2, 3, 4, 5]
evens = [n for n in numbers if n % 2 == 0]
print(f"Even numbers: {evens}")
Which Python concept replaces curly braces for defining code blocks?
What does "batteries included" mean in the context of Python?
Which of the following is a Python-only concept with no direct TypeScript equivalent?
Where can you read the Zen of Python?