mirror of
https://github.com/python/cpython.git
synced 2025-09-27 18:59:43 +00:00
Add example for use cases requiring default values.
This commit is contained in:
parent
7c3738e11c
commit
bc693491eb
1 changed files with 9 additions and 0 deletions
|
@ -492,6 +492,15 @@ the :meth:`__repr__` method:
|
||||||
>>> Point(x=10, y=20)
|
>>> Point(x=10, y=20)
|
||||||
Point(10.000, 20.000)
|
Point(10.000, 20.000)
|
||||||
|
|
||||||
|
Default values can be implemented by starting with a prototype instance
|
||||||
|
and customizing it with :meth:`__replace__`:
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
>>> Account = namedtuple('Account', 'owner balance transaction_count')
|
||||||
|
>>> model_account = Account('<owner name>', 0.0, 0)
|
||||||
|
>>> johns_account = model_account.__replace__(owner='John')
|
||||||
|
|
||||||
.. rubric:: Footnotes
|
.. rubric:: Footnotes
|
||||||
|
|
||||||
.. [#] For information on the star-operator see
|
.. [#] For information on the star-operator see
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue