-4

What is the reason behind having return after defining a function? Please explain in non coding terms. I am trying to understand why to do return and what it actually does instead of just being told to do it.

Riz
  • 9
  • Read [this](http://interactivepython.org/runestone/static/pip2/Functions/Returningavaluefromafunction.html). – iz_ Dec 03 '18 at 02:52

1 Answers1

0

return just simple makes the function give that thing as the value of something, demo:

def f():
    return 'Hello World'

And then you do:

variable=f()

Then now:

print(variable)

Is gonna be:

Hello World

OTOH, print just does this:

def f():
    print('Hello World')

Now:

f()

Is:

Hello World

But:

print(f())

Is:

Hello World
None

And if you do:

variable=f()
print(variable.lower())

The first one will work with .lower() to make it lowercase, but print doesn't, instead, does an error.

U13-Forward
  • 69,221
  • 14
  • 89
  • 114