Program
Lines
Unless otherwise indicated, every input line corresponds to one logical program
statement. Two or more statements can be combined on line input line by inserting
the ; (semicolon) character between adjacent statements. A single statement may
be continued across multiple input lines by ending each line with the \ (back slash)
character. Comments may not be placed after a program line continuation (\)
character on the same input line.
|
Example: Input vs. Program Lines
r = 1; pi = 3.1415927; a = pi * r ** 2
# multiple lines per statement a = \ pi * \ r ** 2 |
Input lines are grouped according to their function. Input lines forming the body of a conditional, loop, exception handler, or function or class definition must be grouped together. Input lines not in any of the construct comprise their own group. In Python, grouping of input lines is indicated by indentation. All lines of a group must be indented the same number of spaces. A horizontal tab character counts as 8 spaces on most systems. In some Python documentation, a group of input lines is called a suite.
|
Example: Input Line Grouping
dist = x2 x1 if dist > 100.: # this is the if conditional group y = dist / 2. z = y ** 2. else : # this is the else conditional group y = dist. z = y ** 2. / 1.5 # back to main script group q = y * z |