Skip to content

Commit 6e0a2fa

Browse files
committed
Add example for argparse's append action
Add an example for `argparse`'s `append` action when a default value is provided.
1 parent 11a5fc8 commit 6e0a2fa

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Doc/library/argparse.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,10 @@ how the command-line arguments should be handled. The supplied actions are:
784784
>>> parser.add_argument('--foo', action='append')
785785
>>> parser.parse_args('--foo 1 --foo 2'.split())
786786
Namespace(foo=['1', '2'])
787+
>>> parser = argparse.ArgumentParser()
788+
>>> parser.add_argument('--foo', action='append', default=['0'])
789+
>>> parser.parse_args('--foo 1 --foo 2'.split())
790+
Namespace(foo=['0', '1', '2'])
787791

788792
* ``'append_const'`` - This stores a list, and appends the value specified by
789793
the const_ keyword argument to the list; note that the const_ keyword

0 commit comments

Comments
 (0)