Statement Syntax
The statement syntax for Python is very simple. In general, each
source line is a single statement. Except for expression
and assignment
statements,
each statement is introduced by a keyword name, such as if
or for
.
Blank lines or remark lines can be inserted anywhere between any statements
in the code. If there is more than one statement on a line, each statement
must be separated by a semicolon (;
).
Very long statements can continue on more than one line. In this
case the statement that is to continue on to the next line must end
with a backslash (\
), for example:
x = "A loooooooooooooooooooong string" + \
"another looooooooooooooooooong string"
When a structure is enclosed by parentheses (()
),
brackets ([]
), or curly braces ({}
),
the statement can be continued on to a new line after any comma, without
having to insert a backslash, for example:
x = (1, 2, 3, "hello",
"goodbye", 4, 5, 6)