python_3,,1 from sys


1 from sys import argv2 one,two,three = argv3 print ‘one is:‘,one4 print ‘two is:‘,two5 print ‘three is:‘,three

bubuko.com,布布扣

参数,解包,变量

from sys import argv

注意:

1.argv 和 raw_input() 有什么不同?
不同点在于用户输入的时机。如果参数是在用户执行命令时就要输入,那就是 argv,如果是在
脚本运行过程中需要用户输入,那就使用 raw_input() 。

1 from sys import argv2 one,two,three = argv3 print ‘one is:‘,one4 print ‘two is:‘,two5 print ‘three is:‘,three6 four = raw_input(‘four:‘)7 print ‘four is : %s‘ %four

bubuko.com,布布扣

2.命令行参数是字符串吗?
是的,就算你在命令行输入数字,你也需要用 int() 把它先转成数字,和在 raw_input()
里一样。

python_3

评论关闭