[Tutor] 'return'

Jennifer Cianciolo jciancio@indiana.edu
Fri May 30 17:46:07 2003


ok, 'return'

I looked around a bit, but I haven't found the FAQ to be all that
helpful yet.  
what is the difference between 'return' and 'print'?  Other than that
print is happy to be written anywhere, return is picky and return can
stop a program if it's sitting there all by itself. right?

thanks



 ###
> >>> import math
> >>> def f(time):
> ...     if time == 0:
> ...         return 0
> ...     return f(time-1) + 1
> ...
> >>> def g(time):
> ...     return 2 * math.sin(time / 3.0)
> ...
> >>> def compose_add(function1, function2):
> ...     def new_function(time):
> ...         return function1(time) + function2(time)
> ...     return new_function
> ...
> >>> fg = compose_add(f, g)
> ###