2014-02-15 54 views
1

我在我的代碼上收到SyntaxError 'return outside function'錯誤。我很感激任何幫助,因爲這讓我感到無法接受。Python:SyntaxError'return'外部函數錯誤

def temp(T, from_unit, to_unit) : # Function for temperature 
     """ Convert between Fahrenheit, Celsius, or Kelvin. Where from_unit and to_unit are temperature units, either 'F' (or 'f') 
     for Fahrenheit, or 'C' (or 'c') for Celsius, or 'K'(or 'k') for Kelvin; and T is a temperature number (of float) for the 
     unit from_unit """ 

    if from_unit == to_unit: 
     return T 
+2

對於那些投票關閉這個問題,我米不太確定這是一個簡單的印刷錯誤。文檔字符串應該不是很明顯因爲大多數新用戶會認爲文檔字符串是一種榮耀的評論,並沒有縮進限制。作爲證據,請看[@BenWhaley](http://stackoverflow.com/a/21805104/1399279)的回答,他稱這個文檔字符串是一個評論(它說明了他們可以很容易被混淆。) – SethMMorton

回答

2

您的文檔字符串比if條件。文檔字符串進一步縮進是Python對象,因此有一部分的代碼確保代碼均勻縮進

2

請注意縮進。

我認爲你需要在同一級別爲「」,」串縮進「if」語句。

+0

你'絕對正確,我設法解決這個錯誤。我已經開始撿起python了,縮進對我來說是個問題。謝謝你的幫助,你們倆。 – Yozuru

+0

我一直在使用Python的年齡和縮進問題仍然推動我的牆壁....適應它! – GreenAsJade

1

語法錯誤:。外面功能 「迴歸」它只是縮進錯誤改變你return語句和錯誤都將丟失