Skip to main content

← All terms · Standard library

dataclasses.field

Configure a dataclass attribute — mutable defaults, init/repr behavior. Use `field(default_factory=list)` to avoid the mutable-default trap.

Learn this interactively:

Open lesson lesson-106

Related — Standard library

pathlib.PathObject-oriented filesystem paths. `Path(".").rglob("*.py")` beats `os.walk + os.collections.CounterDict subclass that counts hashable items: `Counter("hello")` → `{'l': 2, ...}`.itertoolsIterator building blocks — `chain`, `groupby`, `combinations`, `accumulate`. Lazfunctools.cacheMemoize a pure function with `@functools.cache`. Replaces hand-rolled dict cachi