What is the significance of the "return" statement or keyword


#1



Replace this line with your code.


#2

what it says, it returns something (it hands you something back), we can see this:

def example(x,y):
    return x * y
answer = example(5,3)
print example

in the code above, the result of the multiplication is handed back by the function, an stored in answer.


#3

Was just thinking printing the value was more useful as I could see the result, as opposed to just returning the value and the console really doesn't show anything and one is stuck wondering whether the code is right or not.

Thanks for the explanation. Appreciate it.


#4

yea, but once you advance through the course you will see the value of return more

you could also modify the above code a bit:

def example(x,y):
    return x * y
print example(5,3)

just add a print statement in front of the function call, this will print the returned result. Return is very useful. one important thing of return is that the function ends the moment a return keyword is reached.


#5

The last point is an important one to keep in mind:)
Appreciate the help. Thanks.


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.