@@ -692,6 +692,21 @@ how the command-line arguments should be handled. The supplied actions are:
692692 >>> parser.parse_args('--str --int'.split())
693693 Namespace(types=[<class 'str'>, <class 'int'>])
694694
695+ * ``'extend' `` - This stores a list and appends each item from the multi-value
696+ argument list to it.
697+ The ``'extend' `` action is typically used with the nargs _ keyword argument
698+ value ``'+' `` or ``'*' ``.
699+ Note that when nargs _ is ``None `` (the default) or ``'?' ``, each
700+ character of the argument string will be appended to the list.
701+ Example usage::
702+
703+ >>> parser = argparse.ArgumentParser()
704+ >>> parser.add_argument("--foo", action="extend", nargs="+", type=str)
705+ >>> parser.parse_args(["--foo", "f1", "--foo", "f2", "f3", "f4"])
706+ Namespace(foo=['f1', 'f2', 'f3', 'f4'])
707+
708+ .. versionadded :: 3.8
709+
695710* ``'count' `` - This counts the number of times a keyword argument occurs. For
696711 example, this is useful for increasing verbosity levels::
697712
@@ -717,17 +732,6 @@ how the command-line arguments should be handled. The supplied actions are:
717732 >>> parser.parse_args(['--version'])
718733 PROG 2.0
719734
720- * ``'extend' `` - This stores a list, and extends each argument value to the
721- list.
722- Example usage::
723-
724- >>> parser = argparse.ArgumentParser()
725- >>> parser.add_argument("--foo", action="extend", nargs="+", type=str)
726- >>> parser.parse_args(["--foo", "f1", "--foo", "f2", "f3", "f4"])
727- Namespace(foo=['f1', 'f2', 'f3', 'f4'])
728-
729- .. versionadded :: 3.8
730-
731735Only actions that consume command-line arguments (e.g. ``'store' ``,
732736``'append' `` or ``'extend' ``) can be used with positional arguments.
733737
0 commit comments