mirror of
https://github.com/python/cpython.git
synced 2025-09-28 11:15:17 +00:00
Add example for PEP 557. (GH-5383)
This commit is contained in:
parent
f0a95f27c0
commit
4d0296649a
1 changed files with 11 additions and 0 deletions
|
@ -323,6 +323,17 @@ Adds a new module ``dataclasses``. It provides a class decorator
|
||||||
``typing.NamedTuple``, but also works on classes with mutable
|
``typing.NamedTuple``, but also works on classes with mutable
|
||||||
instances, among other features.
|
instances, among other features.
|
||||||
|
|
||||||
|
For example::
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Point:
|
||||||
|
x: float
|
||||||
|
y: float
|
||||||
|
z: float = 0.0
|
||||||
|
|
||||||
|
p = Point(1.5, 2.5)
|
||||||
|
print(p) # produces "Point(x=1.5, y=2.5, z=0.0)"
|
||||||
|
|
||||||
.. seealso::
|
.. seealso::
|
||||||
|
|
||||||
:pep:`557` -- Data Classes
|
:pep:`557` -- Data Classes
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue