[Tutor] functions in Python

Paul D. Eden paul at benchline.org
Mon Apr 17 19:30:31 CEST 2006


This only happens because the python interactive command-line (what you 
get when you just type 'python' in a terminal window) prints return 
values automatically for you.

If you were executing

f(4)

in a program/script, the return value would be lost.

Paul

Payal Rathod wrote:
> On Mon, Apr 17, 2006 at 05:42:05PM +0100, Steve Nelson wrote:
> 
>>When you define a function, you are writing a block of code which you
>>can ask to perform a task.  The task may be simple, and not require
>>any additional information, or it may be more complex and need
>>information.
> 
> 
> What is the difference between,
> 
> 
>>>>def f(x):
> 
> ...     return x
> ...
> 
>>>>f(4)
> 
> 4
> 
> 
>>>>def f(x):
> 
> ...     print x
> ...
> 
>>>>f(4)
> 
> 4
> 
> Both give same results. So, why return statement is needed?
> With warm regards,
> -Payal
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list