2017-02-16 12 views
-2

Pythonのtryexceptブロックでは、except:を指定子なしで使用することができるのであれば、なぜelseが必要なのですか?指定子なしのexpectとelseの違いは?

+1

は、あなたが二番目のを試してみましたか? – khelwood

+0

このリンクをクリックしてください。うまく説明しました。 http://stackoverflow.com/questions/16138232/is-it-a-good-practice-to-use-try-except-else-in-python –

答えて

2

tryexceptelse、およびfinallyはオフの状態です。ここで

https://docs.python.org/2/tutorial/errors.htmlを見てから、一緒にどのようにすべての作業の要約です:

try: 
    #Try something that might raise an exception 
except <exception specifier>: 
    #Code here will only run if the exception that came up was the one specified 
except: 
    #Except clause without specifier will catch all exceptions 
else: 
    #Executed if try clause doesn't raise exception 
    #You can only have this else here if you also have except blocks 
finally: 
    #Runs no matter what 
関連する問題