[Tutor] am I missing another simpler structure?

Gonçalo Rodrigues op73418 at mail.telepac.pt
Thu Dec 16 15:30:22 CET 2004


Loptr Chaote wrote:
> On Wed, 15 Dec 2004 19:58:56 -0500, Brian van den Broek
> 
> 1) Every operation has a return value [unless purposefully left out]
> This includes, but is not limited to; mathematical operations (of
> course), variable assignment, compare blocks, etc..

A small correction: every function has a return value. If left out (that 
is, no return statement) then it returns None. E.g.

 >>> def noret():
... 	2 + 2
... 	
 >>> print noret()
None
 >>>

Statements have no return value, e.g.

 >>> a = 1
 >>> print a = 1
Traceback (  File "<interactive input>", line 1
     print a = 1
             ^
SyntaxError: invalid syntax

Like the above shows, assigment has no return value -- it's a statement. 
This is precisely the distinction between a *statement* (like 
assignment) and an expression (like a function call). Python has this 
distinction like most languages. A language like Scheme doesn't since 
everything is an expression.

With my best regards,
G. Rodrigues


More information about the Tutor mailing list