exercsie13 參數 解包 變量


from sys import argv              
 #從python功能庫中導入功能         “features"真正的名稱是:modules   / libraries

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           #屏幕上顯示第三個變量的名字

$ python ex13.py first 2nd 3rd  #命令行鍵入
The script is called: ex13.py
Your first variable is: first
Your second variable is: 2nd
Your third variable is: 3rd


question 不會解!!!!
結合raw_input和argv寫一個腳本。





from sys import argv  
script, first = argv  
print "How %s are your?" % first  
write = raw_input()  
print "Your %s is %s." % (first, write)  

輸出:
root@he-desktop:~/mystuff# python ex13.py old
How old are your?
25
Your old is 25.

總結:
script(腳本)是在命令行裏給變量
raw_input是屏幕提示鍵盤鍵入變量




finally

from sys import argv  
script, first = argv 
print "How %s are you?" %first
age=raw_input("How %s are you?")
print "I'm %s years %s." %(age, first)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章