14

I just stumbled across several python programs written by different people and I noticed that every function had a return at the end of it

def function01():
    # function
    # events
    # here
    return

I was wondering if it's good python programming practice to include return at the end of functions even if it is not returning anything (purely as a way of ending the function)

Or is it not needed and nothing different will happen in the background?

ZdaR
  • 20,813
  • 6
  • 58
  • 82
TheLovelySausage
  • 3,371
  • 10
  • 48
  • 89
  • 1
    An empty `return` will return `None`. You'll get the same result if you don't use an explicit `return`. – Matthias Apr 28 '15 at 07:03

1 Answers1

22

No, it is not necessary. The function returns after the last line. There is no difference between a simple return and no return.

def foo():
    pass

def bar():
    pass
    return

f = foo()
print(f)
b = bar()
print(b)

Output:

None
None