We’ve just introduced yet another keyword,$_{default}$ . We’ve set it to$_{0}$in order to make it comparable to the other int values. Remember that by default, if an optional argument isn’t specified, it gets the None value, and that cannot be compared to an int value (hence the$_{TypeError}$ exception). And: $ python3 prog.py 4 16 You can go quite far just with what we’ve learned so far, and we have only scratched the surface. The argparse module is very powerful, and we’ll explore a bit more of it before we end this tutorial. What if we wanted to expand our tiny program to perform other powers, not just squares: import argparse parser =argparse.ArgumentParser() parser.add_argument( "x",type=int, help="the base") parser.add_argument( "y",type=int, help="the exponent") parser.add_argument( "-v ","--verbosity ", action="count", default =0) args =parser.parse_args() answer =args.x**args.y if args.verbosity >=2: print(" {} to the power {} equals {} ".format(args .x, args .y, answer)) elif args.verbosity >=1: print(" {} ^ {} == {} ".format(args .x, args .y, answer)) else : print(answer) $ python3 prog.py usage: prog.py [-h] [-v] x y prog.py: error: the following arguments are required: x, y $ python3 prog.py -h usage: prog.py [-h] [-v] x y positional arguments: x the base y the exponent optional arguments: -h, --help show this help message and exit -v, --verbosity $ python3 prog.py 42-v 4^2 == 16 Output: Notice that so far we’ve been using verbosity level to change the text that gets displayed. The following example instead uses verbosity level to display more text instead: import argparse parser =argparse.ArgumentParser() parser.add_argument( "x",type=int, help="the base") parser.add_argument( "y",type=int, help="the exponent") parser.add_argument( "-v ","--verbosity ", action="count", default =0) args =parser.parse_args() answer =args.x**args.y if args.verbosity >=2: print("Running ' {} '".format( __file__ )) (continues on next page) 10 6 Getting a little more advanced