0

for functions that do not return any value, is there any benefit in ending them with either return or return(True) as opposed to just nothing.

I assume there is no performance difference, and Python does not require the statements, but is there a general pythonic convention it is good to follow?

kyrenia
  • 5,431
  • 9
  • 63
  • 93

2 Answers2

0

In general, there is no difference.

Possible difference is when returning from, for example, conditional block. Return will allow you to bypass rest of the block which shouldn't be called anyway.

Also, consider the difference between return(True) and return: return means that the function return value is treated as None, while return(True) is treated as True. This can cause side effects if you conditionally check the return value of a function.

mpolednik
  • 1,013
  • 7
  • 15
0

Sometimes it is useful to end your methods with return self so it's possible to do something like object.a().b()

DeepSpace
  • 78,697
  • 11
  • 109
  • 154