-4

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 :(

YAKOBISAAC
  • 17
  • 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 Answers2

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:

Print and Return, What's the difference

Ori
  • 567
  • 3
  • 9