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))
運行代碼的結果: