Package basics :: Module statement
[hide private]
[frames] | no frames]

Module statement

source code

Python makes a distinction between statements and expressions, though many things are both.

The following variable assignment is a statement not an expression:
>>> X = 3
>>> X
3

The variable X is an expression and has a value 3, which Python echoes when you type X. The statement X=3 has no value, so Python echoes nothing when you type it in.

The following identity test is an expression. The fact that it is an expression means that it has a value:
>>> X == 3 
True
The following arithmetic expression is an expression, which also has a value:
>>> X + 3 
6

Every expression can act as a statement. When you type a lone expression to the Python interpreter, it is acting as a statement. So the generalization about all Python code is that it is a sequence of statements.

Every expression can occur in compound statements:
>>> if X == 3: print 'hi'
...
hi
But the following raises a SyntaxError exception
>>> if X = 3:  print 'hi'  
...
SyntaxError: invalid syntax
Only expressions are allowed as the constituents of compound statements.

Functions [hide private]
  demo_statements()

Function Details [hide private]

demo_statements()

source code 
None