我是python中的新手。我想返回字符串「關閉」,如果s==yes
。請告訴我在下面的代碼中可能出錯。縮進錯誤:預計縮進塊python 3.6
def shut_down(s):
... if s == "yes":
File "<stdin>", line 2
if s == "yes":
^
IndentationError: expected an indented block
我是python中的新手。我想返回字符串「關閉」,如果s==yes
。請告訴我在下面的代碼中可能出錯。縮進錯誤:預計縮進塊python 3.6
def shut_down(s):
... if s == "yes":
File "<stdin>", line 2
if s == "yes":
^
IndentationError: expected an indented block
TL;醫生嘗試爲4個空格添加到您這樣第二行的開始:
def shut_down(s):
if s == "yes"
建議在Python中使用4個空格作爲縮進,列表或不同數量的空格可能有效,但也有時會引起麻煩。更多的可以在PEP8上閱讀。
我不完全確定你是如何試圖縮進第二行的,但重要的是要注意大多數現代Python IDE會自動替換4個空格的製表符,如果你習慣於製表符我個人使用PyCharm,但IDLE也是這樣做的)。
給出空格或標籤。 Python強制縮進。 ...並不意味着光標向前移動,而是寫入一個塊。
複製下面的兩個代碼片段,並嘗試運行
def shut_down(s):
print "Indentation Error"
def shut_down(s):
print "No Indentation Error"
我假設你是在Python函數的定義非常初學者,自定義函數的正確方法是:
#function definition
def shut_down(s):
if s=="yes" :
print("right")
return
shut_down("yes") #calling the function
功能在這裏給你分配「是」 小號變量。
文件 「
文件 「
高清shut_down(S): 如果s == 「是」: 文件 「
您需要使用4個空格進行縮進。
def shut_down(s):
if s == "yes":
刪除點'...'並使用'4個空格或一個製表符'作爲標識。 –
代碼中的小點是什麼?或者你混合選項卡和空間? – danche
歡迎來到SO。請嘗試在平臺上搜索類似的問題,並在發佈您的問題之前閱讀python文檔。 – Sadik