参数, 解包, 变量
- 输入:
# -- coding: utf-8 --
from sys import argv
# import 语句,这是将 Python 的功能模块加入你自己脚本的方法
script, first, second, third = argv
# 将参数变量“argv”解包
print "The script is called:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
-
运行:
在cmd输入打开这个py文件的同时,要输入3个参数才能正常运行
附加题
- 将 raw_input 和 argv 一起使用
from sys import argv
script, a, b = argv
print "The script is called:", script
print "The first variable is:", a
print "The second variable is:", b
y=raw_input("Please input your name\n>")
print "Hello, my name is %s." % y