# A comment | Comment: python interpreter ignores everything to the end of the line. | # This is a comment |
<var> = <expression> | assignment to a variable | favorite_color = "blue" |
<object>.<method>(<params...>) | Call mutator method on the object, passing in additional parameters. | cheeses.append("Venezuelan beaver cheese") |
import <package>, or from <package> import <*> or <list of methods> | import statement | from cs1graphics import * |
<blank line> | ||
for <var> in <sequence>: <body> |
for loop | for ch in range(len(cheeses)): |
print <list of arguments> | print the arguments to output | print "You are 'forgiven'" + " (she said)" |
if <boolean expression>: <body> |
if statement | if x < y: print x |
if <boolean expression>: <body> else: <else-body> |
if-else statement | if x < y: print x else: print y |
if <boolean expression>: <body> elif <boolean expression>: <body> |
if-elif statement (could have else: on the end of it, too) | if x < y: print x elif is_prime(x): print "Is a prime!" |