0

I was looking at some python code at work where somebody has used a return statement even though it was not necessary. It kind of looked like this:

def printSomething():
    print(“......”)
    .
    .
    return

This was done for many such functions. I know this does not make any difference to the output of the function. But, is it a good practice to do so? Or just some programmer idiosyncrasy?

Kaushik
  • 553
  • 3
  • 11
  • 27
  • It's programmer idiosyncrasy because there is no difference between a simple return and no return. – Austin Apr 13 '18 at 10:07
  • 1
    see https://stackoverflow.com/questions/15300550/python-return-return-none-and-no-return-at-all : pretty much the same question, but with every explanation you need – etene Apr 13 '18 at 10:10

1 Answers1

1

No this does absolutely nothing and I would even say its confusing, as in not pythonic, even though it might look ok to a C programmer.

You can safely remove it.

pilu
  • 720
  • 5
  • 16
  • Care to elaborate on why it can be confusing? – Kaushik Apr 13 '18 at 10:08
  • In general the convention seen in most python programs is that a function that only has side effects does not return, in contrast to C for example where a plain `return` is usual (or was back when I had a clue about it) – pilu Apr 13 '18 at 10:11