import argparse## 构造解析器 argparse.ArgumentParser()
parse = argparse.ArgumentParser(description="caculateing the area of rectangle")## 添加参数 .add_argument()
parse.add_argument("--length",type=int,default=20,help='The length of rectangle!')
parse.add_argument('--width',type=int,default=3,help='The width of rectangle!')## 解析参数 .parse_args()
args = parse.parse_args()if __name__=='__main__':result = args.length * args.widthprint("The rectangle's area is :",str(result))
运行代码的结果: