sys 模块笔记-Dstar-note

sys 模块笔记

sys.argv
实现在程序外部传递参数

returns a list of command line arguments passed to a Python script.
返回值为一个命令行列表
list中第0位一般为这个脚本的名字
The item at index 0 in this list is always the name of the script. The rest of the arguments are stored at the subsequent indices.

import sys
print("Hello {}. Welcome to {} tutorial".format(sys.argv[1],sys.argv[2]))
#.format()功能与 %s类似

输出结果:

python test1.py Star python
Hello Star. Welcome to python tutorial.

在Hardway 中理解

if len(sys.argv) == 2 and sys.argv[1] == "english":
#如果sys.argv返回的列表长度为2 且 argv[2]为“english”
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值