dataclasses — Data Classes — Python 3.12.6 documentation
This module provides a decorator and functions for automatically adding generated special methods such as __init__() and __repr__() to user-defined classes. It was originally described in PEP 557. The member variables to use in these generated methods are defined using PEP 526 type annotations. For example, this code: will add, among other things, a __init__() that looks like: Note that this method is automatically added to the class: it is not directly specified in the InventoryItem definition shown above. Added in version 3.7. This function is a decorator that is used to add generated special methods to classes, as described below. The @dataclass decorator examines the class to find fields. A field is defined as a class variable that has a type annotation. With two exceptions described below, nothing in @dataclass examines the type specified in the variable annotation. The order of the fields in all of the generated methods is the order in which they appear in the class definition. T
dataclasses — Data Classes — Python 3.14.6 documentation Navigation index modules | next | previous | Python » 3.14.6 Documentation » The Python Standard Library » Python Runtime Services » dataclasses — Data Classes | Theme Auto Light Dark | dataclasses — Data Classes ¶ Source code: Lib/dataclasses.py This module provides a decorator and functions for automatically adding generated special methods such as __init__() and __repr__() to user-defined classes. It was originally described in PEP 557 . The member variables to use in these generated methods are defined using
related reading
- 9. Classes — Python 3.14.6 documentationdocs.python.org
- Python Classes: The Power of Object-Oriented Programming – Real Pythonrealpython.com
- 3. Data model — Python 3.14.6 documentationdocs.python.org
- class - Why do Python classes inherit object? - Stack Overflowstackoverflow.com
- Glossary — Python 3.14.6 documentationdocs.python.org
- Python Type Annotations Full Guide | docsmissourimrr.github.io
- practical-python | Practical Python Programming (course by @dabeaz)dabeaz-course.github.io
- styleguide | Style guides for Google-originated open-source projectsgoogle.github.io
- Mediumblog.devgenius.io
- The Python pickle Module: How to Persist Objects in Python – Real Pythonrealpython.com
- The @property Decorator in Python: Its Use Cases, Advantages, and Syntaxfreecodecamp.org
- 5. Data Structures — Python 3.14.6 documentationdocs.python.org