argparse Defaults
argparse 默认值
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
| Pattern | Behavior |
|---|---|
action="store_true" | Boolean — True if present, False otherwise. No value follows. |
type=int | argparse calls int(value) for you. |
default=1 | What args.count is when --count isn't passed. |