Two or more physical lines may be joined into logical lines using backslashcharacters (\), as follows: when a physical line ends in a backslash that isnot part of a string literal or comment, it is joined with the following forminga single logical line, deleting the backslash and the following end-of-linecharacter. 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 notcontinue a comment. A backslash does not continue a token except for stringliterals (i.e., tokens other than string literals cannot be split acrossphysical lines using a backslash). A backslash is illegal elsewhere on a lineoutside a string literal.
Expressions in parentheses, square brackets or curly braces can be split overmore than one physical line without using backslashes. For example:
month_names = ['Januari', 'Februari', 'Maart', # These are the 'April', 'Mei', 'Juni', # Dutch names 'Juli', 'Augustus', 'September', # for the months 'Oktober', 'November', 'December'] # of the year
Implicitly continued lines can carry comments. The indentation of thecontinuation lines is not important. Blank continuation lines are allowed.There is no NEWLINE token between implicit continuation lines. Implicitlycontinued lines can also occur within triple-quoted strings (see below); in thatcase they cannot carry comments.
聯(lián)系客服