Modern tooling
uv, ruff, pyproject.toml, packaging, and current Python project workflows.
How to Build a Chainable Filter Helper in Python
A beginner-friendly dataclass helper that chains filters, uniqueness, and slicing on any sequence, returning a plain list at the end.
from dataclasses import dataclass
from typing import Callable, Iterator, Sequence, TypeVar
T = TypeVar("T")
@dataclass
class FilterAssistant:
"""Beginner-friendly helper to filter any collection."""
data: Sequence[T]
def where(self, predicate: Callable[[T], bool]) -> "FilterAssistant":
return …
How to set up mypy strict mode in Python
Demonstrates how to configure and run mypy in strict mode to enforce full type annotation coverage across a Python project.
from typing import Dict, Optional
def describe_user(name: str, age: int, email: Optional[str] = None) -> Dict[str, object]:
"""Build a user description dictionary with strict type annotations."""
user: Dict[str, object] = {"name": name, "age": age}
if email is not None:
user["email"] = email
…
Browse by section
Each section groups closely related Python snippets.
Modern tooling — Python code examples
What you will find here
This page collects modern tooling snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.
Samples vs tutorials and challenges
Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.