我一直在阅读python文档,有人可以帮我解释一下吗?
try_stmt ::= try1_stmt | try2_stmt try1_stmt ::= "try" ":" suite ("except" [expression [("as" | ",") identifier]] ":" suite)+ ["else" ":" suite] ["finally" ":" suite] try2_stmt ::= "try" ":" suite "finally" ":" suite
我最初认为这意味着try语句必须具有任何格式
try
和finally
或
try
,except
,else
和finally
.
但在阅读文档后,它提到了这else
是可选的,也是如此finally
.所以,我想知道文档的目的是什么,向我们展示上面格式的代码?