Simple statements are comprised within a single logical line. Several simple statements may occur on a single line separated by semicolons. The syntax for simple statements is:
简单语句可以在一个逻辑行中表达. 某些简单语句可以用分号分隔而占据一行.简单语句句法如下:
Expression statements are used (mostly interactively) to compute
and write a value, or (usually) to call a procedure (a function
that returns no meaningful result; in Python, procedures return the
value None). Other uses of expression statements are
allowed and occasionally useful. The syntax for an expression
statement is:
表达式语句用于计算和写一个值(多用在交互方式下), 或调用一个过程(一个返回没有意义的结果的函数; 在Python中, 过程返回值None). 其它表达式语句的使用方法也允许, 有时也用的到.表达式语句的句法如下:
An expression statement evaluates the expression list (which may be a single expression).
一个表达式语句要对该表达表(可能只是一个表达式)求值.
In interactive mode, if the value is not None, it
is converted to a string using the built-in repr()function and the
resulting string is written to standard output (see
section 6.6)
on a line by itself. (Expression statements yielding
None are not written, so that procedure calls do not
cause any output.)
在交互方式下, 如果其值不为None, 就使用内建函数repr()并将结果串写入标准输出(见6.6节), 返回None的过程不回写, 所有过程调用没有任何输出.)
Assert statements are a convenient way to insert debugging assertions into a program:
断言语句是一个在程序中插入调试断言的常用方法:
assert_stmt |
::= | "assert"
expression [","
expression] |
The simple form, "assert expression", is equivalent to
简单形式的, "assert expression", 等价于:
if __debug__: if not expression: raise AssertionError
The extended form, "assert expression1, expression2", is equivalent to
扩展形式的, "assert expression", 等价于:
if __debug__: if not expression1: raise AssertionError, expression2
These equivalences assume that __debug__and AssertionError refer
to the built-in variables with those names. In the current
implementation, the built-in variable __debug__ is 1
under normal circumstances, 0 when optimization is requested
(command line option -O). The current code generator emits no code
for an assert statement when optimization is requested at compile
time. Note that it is unnecessary to include the source code for
the expression that failed in the error message; it will be
displayed as part of the stack trace.
这些等价式假定了存在 __debug__ 和 AssertionError , 而不是具有相同名字的相应内建变量.在当前实现, 内建变量__debug__在普通情况下为1, 在要求优化的情况下为0(命令行选项-O) 在编译要求优化时, 当前的代码生成器不产生任何断言语句的代码.注意在错误信息包括源代码的作法是多余的; 因为它们会作为跟踪回溯对象的一部分显示.
Assignments to __debug__ are illegal. The value for
the built-in variable is determined when the interpreter
starts.
给__debug__赋值是非法的,解释器是在启动时读取内建变量的值的.