Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Named arguments

import argparse

parser = argparse.ArgumentParser()
parser.add_argument('--color', help='The name of the color')
args = parser.parse_args()

print(args.color)

python argparse_named.py --color Blue

Blue

python argparse_named.py

None

Named parameters are optional by default. You can pass the required=True parameter to make them required.