Argparse
The `argparse` module makes it easy to write user-friendly command-line interfaces. It handles argument parsing, help messages, error messages, and supports positional/optional arguments, subcommands, and custom types. The guide walks through Basic Argument Parsing, Positional vs Optional, Argument Types & Choices, Subcommands, Custom Actions & Help. Create a parser: `parser = argparse.ArgumentParser(description="...")`. Add arguments: `parser.add_argument("filename")` (positional) or `parser.add_argument("--verbose", "-v")` (optional). Parse: `args = parser.parse_args()`. Access: `args.filename`, `args.verbose`. Positional arguments are required by default and identified by order. Optional arguments start with `--` (long) or `-` (short flag). Use `required=True` on optional args to require them. `default` parameter sets default values for optional arguments. Use `type=int` for integer conversion. `type=float`, `type=open` for file handles (use `argparse.FileType("r")` for better error handling). `choices=["a", "b", "c"]` restricts values. `nargs="+"` requires one or more values. `nargs="*"` accepts zero or more. The guide is organized into 5 sections that build on each other, each pairing a prose explanation with runnable code.