理解Python中raise、assert语句
7.
Simple statements
A simple statement is comprised within a single logical line.
A few simple statements are commonly located on a single line, using semicolons to separate them.
The syntax for simple statements is :
simple_stmt ::= expression_stmt
| assert_stmt
| assignment_stmt
| augmented_assignment_stmt
| annotated_assignment_stmt
| pass_stmt
| del_stmt
| return_stmt
| yield_stmt
| raise_stmt
| break_stmt
| continue_stmt
| import_stmt
| future_stmt
| global_stmt
| nonlocal_stmt
7.1 Expression statements
7.2 Assignment statements
The assignment statements serve the purpose of reassociating variable names with their corresponding values in order to alter the attributes or items of mutable objects.
7.3 The assert statement
Assert statements function as a practical means for inserting debugging assertions into a program.
7.4 The pass statement
pass is a null operation , which means when it is executed, nothing happens.
7.5 The del statement
7.6 The return statement
7.7 The yield statement
7.8 The raise statement
如果在当前作用域中没有任何表达式,则调用raise函数重新抛出最后一个在该作用域内被激活过的异常。若当前作用域中没有被激活的异常,则会抛出一个RuntimeError异常以表明这是一个错误。
Referring to a tutorial, such as tutorial, the definition of raise represents the concept of raise.
The raise keyword is used to throw an error. It allows you to specify the type of error and the corresponding message that will be displayed when this error occurs.
7.9 The break statement
7.10 The continue statement
7.11 The import statement
7.12 The global statement
7.13 The nonlocal statement
References
