datarekha
Section 6 chapters · 41 of 41 lessons

Python

Master Python the way professionals use it today: clean syntax, modern type hints, asyncio for high-throughput LLM apps, Pydantic for safe data, FastAPI for serving, and the engineering practices that ship.

The Python journey 0 / 41 completed
  1. Chapter 01

    Core Language

    12 lessons
  2. 01 Getting Started Read the smallest useful Python program line by line, then set the language up the way professionals actually do — uv, virtual environments, and th… Beginner5 min
  3. 02 Syntax & Style In Python, indentation is not decoration — it is the syntax. Learn the rules, the conventions every team enforces, and the tools that end formattin… Beginner7 min
  4. 03 Variables & Types Python is dynamically typed, yet types still rule everything. Learn what a variable really is — a name, not a box — the core built-in types, and ho… Beginner7 min
  5. 04 Numbers int, float, Decimal, Fraction — and the floating-point quirk that has quietly cost real companies real money. Beginner8 min
  6. 05 Strings Python strings — the methods you will actually use, slicing with negative indices, and the f-string tricks that make code read like prose. Beginner8 min
  7. 06 Lists Python's workhorse collection — append, slice, sort, and the shared-reference gotcha that bites every programmer exactly once. Beginner9 min
  8. 07 Tuples Immutable sequences with hidden superpowers — unpacking, named tuples, and the right tool whenever the answer is 'this should never change.' Beginner7 min
  9. 08 Sets Unordered, unique, and blazingly fast for membership tests — the right tool whenever you would otherwise track what you have already seen. Beginner8 min
  10. 09 Dictionaries Python's most useful data structure — key-value lookups, the .get pattern, and the collections helpers that turn hard problems into one-liners. Beginner9 min
  11. 10 Control Flow if/elif/else, modern match/case, loops, the walrus operator, and the for/else clause that almost nobody knows about. Beginner10 min
  12. 11 Functions Args, kwargs, defaults, keyword-only, type hints — and the mutable-default bug that has made it onto every interview-questions list. Beginner10 min
  13. 12 Comprehensions The Pythonic way to build a list, dict, set, or generator from another iterable — and the honest line between when they help readability and when t… Beginner9 min
  14. Chapter 02

    Pythonic Mid-Level

    12 lessons
  15. 13 Iterators The protocol behind every for-loop in Python — build your own iterators, tell an iterable from an iterator, and stop loading whole datasets into me… Intermediate8 min
  16. 14 Generators Lazy iterators in three lines — stream large files, build pipeline stages, and stop blowing up your RAM. Intermediate9 min
  17. 15 Decorators Wrap any function with logging, retry, caching, or auth — without touching its code. The @ syntax, demystified. Advanced10 min
  18. 16 Context Managers The with statement, why open() is the gold standard, and how to write your own context managers for transactions, temp dirs, and guaranteed teardown. Intermediate9 min
  19. 17 Errors & Exceptions try/except done right — catch specific errors, chain context, raise custom types, and know when NOT to use exceptions at all. Intermediate10 min
  20. 18 Modules & Packages How Python finds your code, the src/ layout professionals use, the __main__ idiom, and the path from one .py file to an installable package. Intermediate9 min
  21. 19 Environments & packaging: venv, uv, pex Where your packages actually install, why uv is 10-100x faster than pip, and how to ship a Python app as one file. Intermediate10 min
  22. 20 File I/O open() with the right mode, the with-statement that closes files for you, and streaming big files without melting your laptop. Beginner8 min
  23. 21 pathlib The modern, object-oriented path API — forget os.path.join, use the / operator and real methods, and stop debugging slashes on Windows. Beginner8 min
  24. 22 Regex The re module essentials — search vs findall, named groups, and the patterns you'll actually use to parse log lines and clean data. Intermediate10 min
  25. 23 datetime & timezones datetime, timedelta, and zoneinfo — the right way to handle dates so you stop shipping bugs at midnight UTC. Intermediate10 min
  26. 24 Logging Why print() stops being acceptable the moment your code runs in production — the logging module, structured logs, and config you can ship. Intermediate9 min
  27. Chapter 03

    OOP & Modern Python

    5 lessons
  28. 25 Classes & Instances class syntax, __init__, methods, properties — the building blocks of object-oriented Python, without the over-engineering. Beginner9 min
  29. 26 Inheritance vs Composition class Child(Parent), super(), abstract base classes — and the 'composition over inheritance' rule that keeps codebases sane. Intermediate9 min
  30. 27 Dunder Methods __repr__, __eq__, __hash__, __len__, __iter__, __call__ — the special methods that make your classes behave like Python's built-ins. Intermediate10 min
  31. 28 dataclasses @dataclass writes __init__, __repr__, and __eq__ for you. The right tool for internal data containers — and when to reach for Pydantic instead. Intermediate9 min
  32. 29 Type Hints Deep Dive Catch bugs before runtime, get real autocomplete, and write docs that don't rot — the pragmatic guide to typing Python today. Intermediate10 min
  33. Chapter 04

    Concurrency & Async

    5 lessons
  34. 30 The GIL Why a Python process runs one bytecode instruction at a time, when that hurts you, and when it doesn't. Advanced8 min
  35. 31 Threading ThreadPoolExecutor — the modern, sane way to do I/O-bound concurrency in Python. Advanced9 min
  36. 32 Multiprocessing Bypass the GIL with real OS processes — when your code is CPU-bound and you want all your cores. Advanced9 min
  37. 33 Asyncio async / await, the event loop, and the small set of primitives that handle thousands of concurrent I/O operations on a single thread. Advanced10 min
  38. 34 Async patterns for LLM apps Fan-out, streaming, rate-limit-aware concurrency, and cancellation — the async primitives every LLM-backed service needs. Advanced10 min
  39. Chapter 05

    Data Validation & APIs

    3 lessons
  40. 35 Pydantic v2 Type hints validate nothing at runtime. Pydantic does — and it is now the de-facto data layer for FastAPI, LLM outputs, and config in modern Python. Intermediate9 min
  41. 36 Pydantic for LLM outputs The killer use case today — define a Pydantic model, hand its JSON schema to an LLM, and get back typed Python objects. No regex, no broken JSON pa… Intermediate9 min
  42. 37 FastAPI Type hints define your API. FastAPI turns a Python function into a validated, documented HTTP endpoint with one decorator — now the default for new… Intermediate10 min
  43. Chapter 06

    Python for LLM Apps

    4 lessons
  44. 38 Tokenization Tokens — not words or characters — are the unit of everything in LLM-land: pricing, context windows, truncation. Here is how they work and how to c… Intermediate8 min
  45. 39 OpenAI & Anthropic SDKs The modern way to call frontier models from Python — the Responses API for OpenAI, the Messages API for Anthropic, side by side with the patterns y… Intermediate9 min
  46. 40 Streaming responses Why streaming halves perceived latency, how server-sent events work under the SDK, and the Python patterns for consuming, aggregating, and cancelli… Intermediate8 min
  47. 41 Embeddings A vector that captures the meaning of text — the building block behind semantic search, recommendations, dedup, and RAG. Cosine similarity, modern… Intermediate8 min
FAQCommon questions

Python — frequently asked questions

Straight answers to the questions people ask most about python.

Do I need to know math to start learning Python?

No. Python's core syntax — variables, loops, functions, lists, and dictionaries — needs nothing beyond basic arithmetic. Math only matters later for specific domains like data science, and even then the Python itself stays simple. Start with the syntax and add math when a project demands it.

What's the difference between a list and a tuple in Python?

A list is mutable (you can add, remove, or change items) and uses square brackets; a tuple is immutable (fixed once created) and uses parentheses. Use a list when the collection will change, and a tuple for fixed records or as dictionary keys, where immutability is required.

Why is my Python code slow — is the GIL to blame?

For CPU-bound work, the Global Interpreter Lock (GIL) stops threads from running Python bytecode in true parallel, so threading won't help — use multiprocessing or vectorised libraries like NumPy. For I/O-bound work the GIL is released during waits, so threads or asyncio do help. Most 'slow Python' is actually unvectorised or algorithmic, not the GIL.

Read the lesson
When should I use a list comprehension instead of a for loop?

Use a comprehension when you're building a new list by transforming or filtering an iterable — it's more concise and usually faster. Stick with a regular for loop when the body has side effects, multiple statements, or complex logic, where a comprehension would hurt readability.

What's the difference between == and is in Python?

`==` checks whether two values are equal; `is` checks whether two names point to the exact same object in memory. Use `==` for value comparison (the common case) and reserve `is` for identity checks like `x is None`.

Skip to content