001、
[root@PC1 test]# ls
hello.py
[root@PC1 test]# cat hello.py
#!/usr/bin/env python
# -*- coding:utf-8 -*-import argparse ## 导入模块parser = argparse.ArgumentParser() ## 创建参数解析器对象 parser
parser.add_argument('--name', type=str, help='Your name') ## 定义一个命令行参数 --name
args = parser.parse_args() ## 解析命令行输入的参数,并把结果保存在 args
中print(f"Hello, {args.name}!")
[root@PC1 test]# python hello.py --name zhangsan
Hello, zhangsan!
。