Python Multi-line Statements
How python interpret multi-line code into single line code:
- python program
- physical lines of code(end with a physical newline CHARACTER create by enter)
- logical lines of code(end with a logical NEWLINE token)
- tokenized
- execute
physical newlines vs logical newline
sometimes physical newlines are ignored in order to combine multiple physical lines into a single logical newline
break implicitly: [], (), {}
1 2 3 4 5 6 7 |
[1, 2, 3] def my_func(a, b, c) pass |
break explicitly
1 2 3 4 |
if a \ and b \ and c: pass |
multi-line strings
multi-line strings are regular string, not comments (can be used as docstring)
escaped characters(\n, \t), non-visible characters(newlines, tabs) in multi-line are part of string; escaped characters will formatted when print it
ref: