@@ -923,6 +923,17 @@ was not present at the command line::
923923 >>> parser.parse_args(''.split())
924924 Namespace(foo=42)
925925
926+ If the ``default `` value is a string, the parser parses the value as if it
927+ were a command-line argument. In particular, the parser applies any type _
928+ conversion argument, if provided, before setting the attribute on the
929+ :class: `Namespace ` return value. Otherwise, the parser uses the value as is::
930+
931+ >>> parser = argparse.ArgumentParser()
932+ >>> parser.add_argument('--length', default='10', type=int)
933+ >>> parser.add_argument('--width', default=10.5, type=int)
934+ >>> parser.parse_args()
935+ Namespace(length=10, width=10.5)
936+
926937For positional arguments with nargs _ equal to ``? `` or ``* ``, the ``default `` value
927938is used when no command-line argument was present::
928939
@@ -961,6 +972,9 @@ types and functions can be used directly as the value of the ``type`` argument::
961972 >>> parser.parse_args('2 temp.txt'.split())
962973 Namespace(bar=<_io.TextIOWrapper name='temp.txt' encoding='UTF-8'>, foo=2)
963974
975+ See the section on the default _ keyword argument for information on when the
976+ ``type `` argument is applied to default arguments.
977+
964978To ease the use of various types of files, the argparse module provides the
965979factory FileType which takes the ``mode= `` and ``bufsize= `` arguments of the
966980:func: `open ` function. For example, ``FileType('w') `` can be used to create a
0 commit comments