請問Python 2.x與3.x一個語法上的差異問題

from sys import argv

script, first, second, third = 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

以上是2.x的程式碼。

在3.x的阪本下,我改成如下
from sys import argv

script, first, second, third = 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


from sys import argv

script, first, second, third = 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)

都會發生錯誤。請問要怎麼改才能在3.x的版本下順利執行?

joshwang wrote:
from sys import...(恕刪)

from sys import argv

script = argv
first = argv
second = argv
third = 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)



照你的程式碼,我這邊可以正常執行啊
文章分享
評分
評分
複製連結

今日熱門文章 網友點擊推薦!