Introduction
Line structure
Logical line
A logical line is constructed from one or more physical lines by following the explicit or implicit line joining rules.
Physical line
A physical line is a sequence of characters terminated by an end-of-line sequence ( LF , CR LF or CR ). The end of input also serves as an implicit terminator for the final physical line.When embedding Python ,source code strings should be passed to Python APIs using C conventions for newline \n (representing ASCII LF).
Comments
A comment starts with a hash character (#) that is not part of a string literal, and ends at the end of the physical line.
Encoding declarations
If a comment in the first or second line of the Python script matches the regular expression coding[=:]\s*([-\w.]+)
(\s*
匹配多个空格,\w
匹配任意字符 a-z|A-Z|0-9
), this comment is processed as an encoding declaration. The recommended forms of an encoding expression are
which is recognized also by GNU Emacs, and
which is recognized by Bram Moolenaar’s VIM .If no encoding declaration is found, the default encoding is UTF-8.