(continued from previous page) And now the output: 6 import argparse parser =argparse.ArgumentParser() parser.add_argument( "square",type=int, help="display a square of a given number ") parser.add_argument( "-v ","--verbose ", action="store_true", help="increase output verbosity ") args =parser.parse_args() answer =args.square**2 if args.verbose: print("the square of {} equals {} ".format(args .square, answer)) else : print(answer) $ python3 prog.py -v verbosity turned on $ python3 prog.py --help usage: prog.py [-h] [-v] optional arguments: -h, --help show this help message and exit -v, --verbose increase output verbosity import argparse parser =argparse.ArgumentParser() parser.add_argument( "-v ","--verbose ", help="increase output verbosity ", action="store_true") args =parser.parse_args() if args.verbose: print("verbosity turned on") -h, --help show this help message and exit --verbose increase output verbosity Here is what is happening: If you are familiar with command line usage, you will notice that I haven’t yet touched on the topic of short versions of the options. It’s quite simple: And here goes: Note that the new ability is also reflected in the help text. Our program keeps growing in complexity: 5 Combining Positional and Optional arguments 4.1 Short options • The option is now more of a flag than something that requires a value. We even changed the name of the option to match that idea. Note that we now specify a new keyword, action , and give it the value "store_true" . This means that, if the option is specified, assign the value True to args.verbose . Not specifying it implies$_{False}$. • It complains when you specify a value, in true spirit of what flags actually are. • Notice the different help text.