Skip to content

Commit dae00d8

Browse files
authored
Add example for argparse's append action
Add an example for `argparse`'s `append` action when a default value is provided.
1 parent a936af9 commit dae00d8

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
@@ -754,6 +754,10 @@ how the command-line arguments should be handled. The supplied actions are:
754754
>>> parser.add_argument('--foo', action='append')
755755
>>> parser.parse_args('--foo 1 --foo 2'.split())
756756
Namespace(foo=['1', '2'])
757+
>>> parser = argparse.ArgumentParser()
758+
>>> parser.add_argument('--foo', action='append', default=['0'])
759+
>>> parser.parse_args('--foo 1 --foo 2'.split())
760+
Namespace(foo=['0', '1', '2'])
757761

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

0 commit comments

Comments
 (0)