A Python program is divided into a number of logical lines.
一个Python程序被分成多个逻辑行.
The end of a logical line is represented by the token NEWLINE. Statements cannot cross logical line boundaries except where NEWLINE is allowed by the syntax (e.g., between statements in compound statements). A logical line is constructed from one or more physical lines by following the explicit or implicit line joining rules.
逻辑行以一个NEWLINE(新行)语言符号结束, 语句不能跨多个逻辑行, 除非语法上允许NEWLINE(例如, 在复合语句的中的语句序列).一个逻辑行由一个物理行, 或者以显式/隐式行连接规则连接的多个物理行构成.
A physical line ends in whatever the current platform's convention is for terminating lines. On Unix, this is the ASCII LF (linefeed) character. On Windows, it is the ASCII sequence CR LF (return followed by linefeed). On Macintosh, it is the ASCII CR (return) character.
一个物理行由所在平台的断行符号结束.在Unix上, 是ASCII LF(换行)字符; 在DOS/Windows上, 是ASCII字符序列CR LF(回车加换行); 在Macintosh上, 是ASCII CR(回车)字符.
A comment starts with a hash character (#) that is
not part of a string literal, and ends at the end of the physical
line. A comment signifies the end of the logical line unless the
implicit line joining rules are invoked. Comments are ignored by
the syntax; they are not tokens.
一个注释以#字符(此时, 它不能是串字面值的一部分)开始,结束于该物理行的结尾.如果没有隐式的行连接,
那么注释就意味着该逻辑行的终止.注释为句法分析所忽略, 它们不记作语言符号.
If a comment in the first or second line of the Python script matches the regular expression coding[=:]\s*([\w-_.]+), this comment is processed as an encoding declaration; the first group of this expression names the encoding of the source code file. The recommended forms of this expression are
# -*- coding: <encoding-name> -*-
which is recognized also by GNU Emacs, and
# vim:fileencoding=<encoding-name>
which is recognized by Bram Moolenar's VIM. In addition, if the
first bytes of the file are the UTF-8 byte-order mark
('\xef\xbb\xbf'), the declared file encoding is UTF-8
(this is supported, among others, by Microsoft's notepad).
If an encoding is declared, the encoding name must be recognized by Python. The encoding is used for all lexical analysis, in particular to find the end of a string, and to interpret the contents of Unicode literals. String literals are converted to Unicode for syntactical analysis, then converted back to their original encoding before interpretation starts. The encoding declaration must appear on a line of its own.