https://github.com/python/cpython/commit/fa6dbb16419dacb57cb831b1fac5a32fef4f412d
commit: fa6dbb16419dacb57cb831b1fac5a32fef4f412d
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: savannahostrowski <[email protected]>
date: 2025-09-17T17:35:37+01:00
summary:

[3.13] GH-139067: Add example for `argparse`'s `append` action (GH-131389) 
(#139069)

GH-139067: Add example for `argparse`'s `append` action (GH-131389)
(cherry picked from commit 101fd33065638c94f413447a7bcff09d54831a4a)

Co-authored-by: Moshe Kaplan <[email protected]>

files:
M Doc/library/argparse.rst

diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index 11b3b2a7e9b2f1..3b9dde39814adf 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -687,16 +687,16 @@ how the command-line arguments should be handled. The 
supplied actions are:
     >>> parser.parse_args('--foo --bar'.split())
     Namespace(foo=True, bar=False, baz=True)
 
-* ``'append'`` - This stores a list, and appends each argument value to the
-  list. It is useful to allow an option to be specified multiple times.
-  If the default value is non-empty, the default elements will be present
-  in the parsed value for the option, with any values from the
-  command line appended after those default values. Example usage::
+* ``'append'`` - This appends each argument value to a list.
+  It is useful for allowing an option to be specified multiple times.
+  If the default value is a non-empty list, the parsed value will start
+  with the default list's elements and any values from the command line
+  will be appended after those default values. Example usage::
 
     >>> parser = argparse.ArgumentParser()
-    >>> parser.add_argument('--foo', action='append')
+    >>> parser.add_argument('--foo', action='append', default=['0'])
     >>> parser.parse_args('--foo 1 --foo 2'.split())
-    Namespace(foo=['1', '2'])
+    Namespace(foo=['0', '1', '2'])
 
 * ``'append_const'`` - This stores a list, and appends the value specified by
   the const_ keyword argument to the list; note that the const_ keyword

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to