Can somebody please teach me how to do return? I am doing a course and I just don't understand what return is for and how to use it :(
Asked
Active
Viewed 40 times
-4
-
https://realpython.com/python-return-statement/ – Nin17 Jul 01 '22 at 14:45
-
As you're in a class, I suggest you talk to your teacher or a tutor; the *really* basic elements of programming can't be taught a StackOverflow question at a time. – ShadowRanger Jul 01 '22 at 14:51
2 Answers
0
return is used when defining function so it returns the result of this function.
example:
def test():
return(1)
it returns 1
def test2(a,b):
return(a+b)
it returns the sum of the two values

Ran A
- 746
- 3
- 7
- 19
0
A return statement is used to end the execution of the function call and “returns” the result. The statements after the return statement are not executed
For example:
def cube(x):
r = x**3
return r
Maybe this could help you as well:

Ori
- 567
- 3
- 9