
Statements and Syntax
|
35
Statements and Syntax
This section describes the rules for syntax and variable
names.
Syntax Rules
Here are the general rules for writing Python programs.
Control flow
Statements execute one after another, unless control-flow
statements are used (
if, while, for, raise, calls, etc.).
Blocks
A block is delimited by indenting all of its statements by
the same amount, with spaces or tabs. A tab counts for
enough spaces to move the column to a multiple of 8.
Blocks can appear on the same line as a statement header
if they are simple statements.
Statements
A statement ends at the end of a line, but can continue
over multiple lines if a physical line ends with a
\,an
unclosed
(), [],or{} pair, or an unclosed, triple-quoted
string. Multiple simple statements can appear on a line if
they are separated with a semicolon (
;).
Comments
Comments start with a
# (not in a string constant) and
span to the end of the line.
hex(X), oct(X),
str(X)
Integer types Hexadecimal, octal,
decimal strings
ord(C), chr(I) Character, integer code Integer code, character
a
In Version 2.2, converter functions (e.g., int, float, str) are also available as class constructors,
and can be subclassed.
Table 11. String/object converters (continued)
Converter Converts from Converts to