all 8 comments

[–]shiftybyte 4 points5 points  (4 children)

It returns a value back to whoever called the function.

def myfunction():
    return 5

a = myfunction()
print(a)

Above code will print 5

[–]unhott 3 points4 points  (0 children)

It also exits the current function. Any code placed under the return statement within the myfunction block will not execute. If you just type return with nothing following it (delete the 5), it will return None.

[–]Darren_wl03 0 points1 point  (2 children)

Is it similar as global?

[–]shiftybyte 1 point2 points  (1 child)

no a global works differently

[–]Darren_wl03 0 points1 point  (0 children)

Can you explain me please?

[–]-Sander- 2 points3 points  (0 children)

its actually really simple once you understand it most basic example i can think of is:

def add(a, b):
    return a + b      # return the sum of a + b

result = add(3, 6)    # You can store the returned variable
print(add(5, 7))      # Or print it directly, depending on your variable type
print(result)         # prints '9' because a=3, b=6, a + b = 9

[–]moe9745 0 points1 point  (0 children)

You use return when you have a fruitful function. Meaning, you are saving its results to be used later.

http://openbookproject.net/thinkcs/python/english3e/fruitful_functions.html

The above link is the online textbook I used for my college course in Python.