笨办法学python3练习代码13-14:argv参数变量的学习
2024-08-30 00:30:33
ex13.py argv参数的学习
#argv:参数变量(argument variable),这是一个标准的编程术语,在其他语言中也可可以看到.argument可译为: 参数 #如果参数是用户在执行命令时就要输入,用argv.命令行参数都是字符串
#如果参数是在脚本运行过程中需要用户输入 ,用input()
from sys import argv
#read the WYSS section for how to run this #将argv解包(unpack),把参数赋值给4个变量:script,first,second,third 。例如执行时 python ex13.py 1 2 3 分别对应参数script,first,second,third.
script,first,second,third = argv
#python ex13.py 1 22 33 与script,first,second,third一一对应 print("The script is called: ",script)
print("Your first variable is: ",first)
print("YOur second variable is: ",second)
print("Your third variable is: ",third) #与input()结合使用
x = input("what's your name ?.")
print(x)
ex14.py
from sys import argv
script, user_name = argv #把提示符赋值给prompt变量
prompt = '>>>>' #将字符串'>>>>' 赋给变量prompt #print(f"字符串"),前面的f表示print为格式化输出
print(f"Hi {user_name}, I'm the {script} script.")
print("I'd like to ask you a few question.")
print(f"Do you like me {user_name}?")
likes = input(prompt) #原样输出prompt = '>>>>'这个提示符后,读取用户自己输入的信息 print(f"Where do you live {user_name}?")
lives = input(prompt) #原样输出prompt = '>>>>'这个提示符后,读取用户自己输入的信息 print("What kind of computer do you have ?")
computer = input(prompt) #多行字符串格式化打印
print(f"""
Alright,so you said:{likes} about liking me.
You live in {lives}. Not sure where that is.
And you have a {computer} computer .Nice
""")
最新文章
- cocos2dx的android版FileUtils的坑
- intel82599在centos6.5下编译安装
- Routing in ASP.NET Web API和配置文件的设定读取
- atitit.提升稳定性---hibernate 增加重试retry 机制解决数据库连接关闭
- json返回日期格式化的解决
- 各式各样table
- javascript里面支持el表达式和<;s:iterator>;
- kettle Java Filter(表达式过滤)
- 编码神器之sublime(插件安装)
- php 的一个pg_fetch_assoc的怪问题
- ckeditor字数限制
- Java API设计CheckList
- Codeforces 707D Persistent Bookcase(时间树)
- 【课程分享】基于plusgantt的项目管理系统实战开发(Spring3+JDBC+RMI的架构、自己定义工作流)
- MingQQ v1.0高仿版开源了,使用WebQQ协议实现了QQ客户端基本的聊天功能...
- Linux系统查看有几块硬盘
- Dos.Common
- 解决mysql使用GTID主从复制错误问题
- JMS学习以及jms的实现activeMq
- Windows修改默认远程端口号3389
热门文章
- 小程序报错 parameter.content should be String instead of Undefined;
- day47 作业
- day10 基本数据类型(下)
- day17 作业
- FileBeat yml配置文件 -常用参数详解
- 机器学习实战基础(二十四):sklearn中的降维算法PCA和SVD(五) PCA与SVD 之 重要接口inverse_transform
- JavaScript:父页面与Iframe页面方法互调
- MVC + EFCore 项目实战 - 数仓管理系统4 – 需求分解
- 区分C语言中的指针函数和函数指针
- 小白从零开始阿里云部署react项目+node服务接口(三:部署到服务器)