2016-05-23 9 views
0

Python 3.5.1でIndentationErrorがスローされ、SyntaxErrorがスローされることがあるので、どちらの場合でもIndentationErrorを投げると思っています。例えば:その行は、それがされている必要があり以上のインデントされたためPython IndentationErrorとSyntaxErrorを理解する

1)

>>> if True: 
...  pass 
...    else: 
    File "<stdin>", line 3 
    else: 
    ^
IndentationError: unexpected indent 

2)

>>> if True: 
...  pass 
...  else: 
    File "<stdin>", line 3 
    else: 
    ^
SyntaxError: invalid syntax 

答えて

5

IndentationErrorです。 passは、次の行をインデントする必要はありません。それはpassまたはwhileのような他のいくつかの文を持っていた、通訳が必要なこの文を見つけることができなかった場合elseステートメントの行は理論的forwhileelifif(適切にインデントすることができるが、あるためSyntaxErrorがある

、またはexcept)を入力します。

関連する問題