argparse.add_argument()
argparse.add_argument() is a Python method in the Argparse Module category. Defines a command-line argument the parser should accept. The syntax is argparse.add_argument(*name_or_flags, action=None, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, dest=None). Parameters: name_or_flags, type, help, etc.. Returns: Action object. A typical example: parser.add_argument("--verbose", "-v", action="store_true", help="increase output verbosity"). A close sibling is argparse.ArgumentParser(), which creates an argument parser for processing command-line arguments. A close sibling is argparse.parse_args(), which parses the command-line arguments and returns a Namespace object. A close sibling is argparse.Namespace, which the default namespace object used by parse_args(). More about this category: Command-line argument parsing — ArgumentParser, add_argument. For a broader walkthrough, read the Argparse Module guide. Related Argparse Module entries: argparse.ArgumentParser(), argparse.parse_args(), argparse.Namespace. This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try argparse.add_argument() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.