Lets say I define a simple function which will display an integer passed to it:
def funct1(param1):
print(param1)
return(param1)
the output will be the same but and I know that when a return statement is used in a function the output can be used again. Otherwise the value of a print statement cannot be used. But I know this is not the formal definition, Can anyone provide me with a good definition?
Dramatically different things. Imagine if I have this python program:
What do you expect to be the output?
Why?
Why? Because
printtakes its arguments/expressions and dumps them to standard output, so in the functions I made up,printwill output the value ofx, which ishello.printAndReturnwill returnxto the caller of the method, so:ret = printAndReturn()retwill have the same value asx, i.e."hello"printAndReturnNothingdoesn’t return anything, so:other = printAndReturnNothing()otheractually becomesNonebecause that is the default return from a python function. Python functions always return something, but if noreturnis declared, the function will returnNone.Resources
Going through the python tutorial will introduce you to these concepts: http://docs.python.org/tutorial
Here’s something about functions form python’s tutorial: http://docs.python.org/tutorial/controlflow.html#defining-functions