Multi-Line Statements:
Statements in Python
typically end with a new line. Python does, however, allow the use
of the line continuation character (\) to denote that the line
should continue.
total = item_one + \
item_two + \
item_three
days = ['Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday']
Quotation in Python:
Python accepts single
('), double (") and triple (''' or """) quotes to denote string
literals, as long as the same type of quote starts and ends the
string.
The triple quotes can be used to span the string across
multiple lines
word =
'word'
sentence
= "This is a
sentence."
paragraph = """This is a paragraph. It
is
made up of
multiple lines and sentences."""
Comments in Python:
A hash sign (#) that is
not inside a string literal begins a comment. All characters after
the # and up to the physical line end are part of the comment, and
the Python interpreter ignores them.
#!/usr/bin/python # First
comment
print "Hello, Python!"; # second comment
Using Blank Lines:
A line containing only
whitespace, possibly with a comment, is known as a blank line, and
Python totally ignores it.
In an interactive interpreter session,
you must enter an empty physical line to terminate a multiline
statement.
Multiple Statements on a Single Line:
The
semicolon ( ; ) allows multiple statements on the single line given
that neither statement starts a new code block. Here is a sample
snip using the
semicolon:
import sys;
x = 'foo'; sys.stdout.write(x + '\n')
Multiple Statement Groups as Suites:
Groups
of individual statements making up a single code block are called
suites in Python.
Compound or complex statements, such as if,
while, def, and class, are those which require a header line and a
suite.
Header lines begin the statement (with the keyword) and
terminate with a colon ( : ) and are followed by one or more lines
which make up the
suite.
if expression
:
suite
elif
expression
:
suite
else
:
suite