[英]Why does the following code shows an error?
每當我運行以下代碼時,它將引發錯誤。
from sys import argv
script, first, second, third = argv
print "The script is called:", scrip
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
錯誤出現-
File "/Users/rishabh/Documents/rishabh.py", line 3
script, first, second, third ,fourth= argv
^
IndentationError: unexpected indent
解:
from sys import argv
script, first, second, third = argv
print "The script is called:", scrip
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
只需復制並運行。 它應該工作:p
正如丹尼爾(Daniel)所說:“因為您已經縮進了,所以不應該嗎?”
Python對縮進很敏感。 每個縮進都必須是相同數量的單位,無論是單個縮進還是兩個空格縮進,甚至是(如果需要)30個制表符!
在您的代碼中,每條打印語句行上都有一個(最可能)偶然的空間。 因為它們不需要縮進(如果它們在if
語句中,或者它們會進行某種排序),則if會引發錯誤。 解釋器根本無法理解為什么要縮進。
正確的代碼(空格已刪除):
from sys import argv
script, first, second, third = argv
print "The script is called:", scrip
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
“腳本”一詞前有一個空格(縮進)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.