From: Raymond Hettinger Date: Thu, 15 Nov 2007 22:39:34 +0000 (+0000) Subject: Add example for use cases requiring default values. X-Git-Tag: v2.6a1~1051 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bc693491eb357d5683473c22af3db867b4c0141d;p=thirdparty%2FPython%2Fcpython.git Add example for use cases requiring default values. --- diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 89885abd7659..bdc0b86a5917 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -492,6 +492,15 @@ the :meth:`__repr__` method: >>> Point(x=10, y=20) 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('', 0.0, 0) + >>> johns_account = model_account.__replace__(owner='John') + .. rubric:: Footnotes .. [#] For information on the star-operator see