Data Modeling and Utility Modules

dataclasses

Generates methods such as initialization and representation for classes with annotated fields. Annotations describe fields but do not validate their values. Use field(default_factory=...) for fresh mutable defaults. frozen=True restricts field assignment but does not recursively freeze contained objects.

Formal Syntax & Structure

python syntaxpython
import dataclasses

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
from dataclasses import dataclass@dataclassclass Item:    name: str    count: int = 1print(Item("Tea"))
Python Reference