Named arguments



examples/argparse/argparse_named.py
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.