What does return do?


#1

Hello

I was wondering what does return do?
I understand it returns something as output
But I'm confused as to what that output can be used for / how that output can be captured?

I understand that

x = some_function(args*)

will store the output of some_function(args*), which would make it usable for capturing outputs?
Or does it store the function itself and calls it when the variable "x" is called?

Thank you


#2

Return stores a value in the interface.


#3

yes, you know captured the value returned by your function in x, this can be useful if you need to further manipulation with the result of the function.

the return keyword will also end a function, quit important to understand

functions can also call other functions which can return values, for example you will build a cube function which give the cube (^3) of a number, and a divislbe_by_three function, which will return the cube() of number if divisible by 3.


#4

What is "the interface"?


#5

When I say interface, I generally refer to the whole program.


#6

both interface and whole program are not correct terms here.

There are two things you can do with a return value: printing by adding a print keyword before the function call or storing the returned result in a variable


#7

The second thing is what I met. I am sorry for not using the correct terms.


#9

function returns None by default, so in the first method you capture None in x

Hope it all makes sense now

we use the return keyword to overwrite the default


#11

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