笨办法学python3练习代码13-14:argv参数变量的学习
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
""")
笨办法学python3练习代码13-14:argv参数变量的学习的更多相关文章
- 笨办法学python3练习代码ex21.py
def add(a, b): print(f"ADDING {a} + {b}") return (a + b) def subtract(a, b): #subtract :减去 ...
- 笨办法学python3练习代码ex18.py
#命名.变量.代码.函数 #this one is like your scripts with argv def print_two(*args): arg1, arg2 = args #将参数解包 ...
- 笨办法学python3练习代码ex19.py
定义函数的语法: def 函数名(参数) (语句) #函数和变量 #函数里的变量与脚本里的变量是没有联系的. def cheese_and_crackers(cheese_count,boxes_o ...
- 笨办法学python3练习代码11-12:print()
ex11.py print("How old are you? ",end = " ") #加入end = " ",则函数不再自动换行 ag ...
- 《笨办法学Python3 》入坑必备,并不是真笨学!!!
<笨办法学Python3 >免费下载地址 内容简介 · · · · · · 本书是一本Python入门书籍,适合对计算机了解不多,没有学过编程,但对编程感兴趣的读者学习使用.这本书以习题的 ...
- [IT学习]Learn Python the Hard Way (Using Python 3)笨办法学Python3版本
黑客余弦先生在知道创宇的知道创宇研发技能表v3.1中提到了入门Python的一本好书<Learn Python the Hard Way(英文版链接)>.其中的代码全部是2.7版本. 如果 ...
- 笨办法学python3代码练习ex23.py 字符串字节串字符编码
首先简单说一下字符编码的问题.平常遇到比较多的就是ASCII码(全称:美国信息交换标准码).ASCII码使用一个字节(8位)来表示一些常见的数字.英文字母以及一些控制字符.英语用128个符号编码就够了 ...
- 笨办法学Python3习题19
学习笔记记录一下 def cheese_and_crackers(cheese_count, boxes_of_crackers): print (f"You have {cheese_co ...
- 笨办法学python 13题:pycharm 运行
笨办法学python 13题 代码: # -*- coding: utf-8 -*- from sys import argv # argv--argument variable 参数变量 scrip ...
随机推荐
- 微服务框架Demo.MicroServer运行手册
一.背景说明: 之前分享过一个微服务开发框架, "享一个集成.NET Core+Swagger+Consul+Polly+Ocelot+IdentityServer4+Exceptionle ...
- 使用CodeMirror插件遇到的问题
CodeMirror的正常使用: //首先通过<script>标签引入相应的js,这个就不必说了 var myCodeMirror = CodeMirror.fromTextArea(my ...
- vue重置data里的值
this.$options.data() 这个可以获取原始的data值,this.$data 获取当前状态下的data,拷贝重新赋值一下就行了. Object.assign(this.$data, t ...
- js 自定义阻止事件冒泡函数
// 以下改方法全兼容Chrome function stopBubble(event){ if(event.stopPropagation){ // 兼容火狐(firebox) event.st ...
- bilibili自定义调整视频播放速度
自定义调整视频播放速度 在b站的播放页面,按下f12,打开控制台 在控制台中复制下面代码,想几倍速就把2.5改成你想要的播放速度 document.querySelector('video').pla ...
- 如何用 Python 做自动化测试【进阶必看】
一.Selenium 环境部署 1. window 环境部署 1.1 当前环境Win10 64 位系统:Python3.6.2(官方已经更新到了 3.6.4) 官方下载地址:https://www.p ...
- 第四章:View的工作原理
4.1 ViewRoot和DecorView ViewRoot对应于ViewRootImplement类,它是连接WindowManager和DecorView的纽带,View的三大流程均是通过Vie ...
- 使用数据泵(expdp、impdp)迁移数据库流程
转载原文地址为:http://blog.itpub.net/26736162/viewspace-2652256/ 使用数据泵迁移数据库流程 How To Move Or Copy A Databas ...
- ant design pro 实战 : 使用 ztree
应当指出,antd 是有 ztree 组件的,但是太简单,无法满足复杂的业务需求. 所以我还是决定使用zTree. 用 npm | cnpm 或者 yarn | tyarn 安装,这一步略. 在 js ...
- Lucas定理 & Catalan Number & 中国剩余定理(CRT)
又双叒叕来水数论了 今天来学习\(Lucas \:\ \& \:\ Catalan Number\) 两者有着密切的联系(当然还有CRT),所以放在一起学习一下 \(Lucas\) 定义\(\ ...