Skip to content

Commit 1f9516a

Browse files
Add clarification on nargs='*' positional default behavior
1 parent 6544bf4 commit 1f9516a

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

Doc/library/argparse.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,10 @@ is used when no command-line argument was present::
10521052
>>> parser.parse_args([])
10531053
Namespace(foo=42)
10541054

1055+
Because ``nargs='*'`` collects matched values into a list, an absent positional
1056+
argument yields an empty list (``[]``); a default of ``None`` is replaced by
1057+
``[]``, although any other default is used as given.
1058+
10551059
For required_ arguments, the ``default`` value is ignored. For example, this
10561060
applies to positional arguments with nargs_ values other than ``?`` or ``*``,
10571061
or optional arguments marked as ``required=True``.

0 commit comments

Comments
 (0)