W WolfCode · CSC 141

argparse Defaults

argparse 默认值

≈ 20 min · python-cmdline · Open in WolfCode

type= converts strings for you. default= fills in when the flag isn't given. Two changes that turn a toy parser into a real one.

Python · runnable

What action / type / default each does

PatternBehavior
action="store_true"Boolean — True if present, False otherwise. No value follows.
type=intargparse calls int(value) for you.
default=1What args.count is when --count isn't passed.