笨办法学Python ex13

2016-12-10  本文已影响0人  Joemini

参数, 解包, 变量


# -- 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个参数才能正常运行


附加题

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
上一篇 下一篇

猜你喜欢

热点阅读