dataclasses

Stdlib — DataPython 3.7+Intermediate

Decorator for auto-generating class boilerplate (__init__, __repr__, etc.)

Quick Info

Documentation
Official Docs
Python Version
3.7+
Dependencies
None — Python Standard Library
Install
Included with Python

Learn by Difficulty

Quick Example

python
from dataclasses import dataclass, field

@dataclass
class Point:
    x: float
    y: float

@dataclass
class Person:
    name: str
    age: int
    hobbies: list = field(default_factory=list)

p = Point(3.0, 4.0)
print(p)

person = Person("Alice", 30, ["reading", "coding"])
print(person)

The dataclasses module is part of Python's standard library. Decorator for auto-generating class boilerplate (__init__, __repr__, etc.).

Try in Playground

Tags

stdliboopdata-structuredatatypedecorator

Related Items