Two or more physical lines may be joined into logical lines using
backslash characters (\
), as follows: when a physical line ends
in a backslash that is not part of a string literal or comment, it is
joined with the following forming a single logical line, deleting the
backslash and the following end-of-line character. For example:
两个或更多物理行可以使用反斜线字符(\
)合并成一个逻辑行, 具体地说: 当一个物理行结束在一个反斜线(此时, 这个反斜线不能是串字面值或注释的一部分)处时,它就同下面的物理行合并成一个逻辑行,同时将反斜线和跟着的行结束符删除。
if 1900 < year < 2100 and 1 <= month <= 12 \ and 1 <= day <= 31 and 0 <= hour < 24 \ and 0 <= minute < 60 and 0 <= second < 60: # Looks like a valid date return 1
A line ending in a backslash cannot carry a comment. A backslash does not continue a comment. A backslash does not continue a token except for string literals (i.e., tokens other than string literals cannot be split across physical lines using a backslash). A backslash is illegal elsewhere on a line outside a string literal.
以反斜线结尾的行不能在其后加注释, 反斜线不能续注释行. 除了串字面值, 也不能续语言符号(也就是说,其它不是串字面值的语言符号不能通过反斜线横跨数个物理行). 在串字面值之外其它地方出现的反斜线都是非法的.