Pelokalan
Python ID
id en
Masuk
Proyek
whatsnew__3-10.po Berkas proyek · python-docs-id-3.14 · Bahasa Indonesia
Modul PO Hanya lihat
Teks sumber — English
Terjemahan — Bahasa Indonesia
You can use positional parameters with some builtin classes that provide an ordering for their attributes (e.g. dataclasses). You can also define a specific position for attributes in patterns by setting the ``__match_args__`` special attribute in your classes. If it's set to ("x", "y"), the following patterns are all equivalent (and all bind the ``y`` attribute to the ``var`` variable)::
dataclasses
dataclasses
Added ``slots`` parameter in :deco:`dataclasses.dataclass` decorator. (Contributed by Yurii Karabas in :issue:`42269`)
dataclasses now supports fields that are keyword-only in the generated __init__ method. There are a number of ways of specifying keyword-only fields.
from dataclasses import dataclass @dataclass(kw_only=True) class Birthday: name: str birthday: datetime.date
from dataclasses import dataclass, field @dataclass class Birthday: name: str birthday: datetime.date = field(kw_only=True)
Here only ``birthday`` is keyword-only. If you set ``kw_only`` on individual fields, be aware that there are rules about re-ordering fields due to keyword-only fields needing to follow non-keyword-only fields. See the full dataclasses documentation for details.
from dataclasses import dataclass, KW_ONLY @dataclass class Point: x: float y: float _: KW_ONLY z: float = 0.0 t: float = 0.0
:mod:`pprint` can now pretty-print :class:`dataclasses.dataclass` instances. (Contributed by Lewis Gaul in :issue:`43080`.)