summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2007-11-15 22:39:34 (GMT)
committerRaymond Hettinger <python@rcn.com>2007-11-15 22:39:34 (GMT)
commitbc693491eb357d5683473c22af3db867b4c0141d (patch)
treebe64342c5d07a7a07988a717801828ab974c09d5
parent7c3738e11c35a7ac1c4ea8bdff9ec4d906db537e (diff)
downloadcpython-bc693491eb357d5683473c22af3db867b4c0141d.zip
cpython-bc693491eb357d5683473c22af3db867b4c0141d.tar.gz
cpython-bc693491eb357d5683473c22af3db867b4c0141d.tar.bz2
Add example for use cases requiring default values.
-rw-r--r--Doc/library/collections.rst9
1 files changed, 9 insertions, 0 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index 89885ab..bdc0b86 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('<owner name>', 0.0, 0)
+ >>> johns_account = model_account.__replace__(owner='John')
+
.. rubric:: Footnotes
.. [#] For information on the star-operator see