When looking through Python code on GitHub, I've seen several examples of a return
with no value. For example:
if hasattr(self, 'moved_away'):
return
# and here code continues
What does the empty return mean?
When looking through Python code on GitHub, I've seen several examples of a return
with no value. For example:
if hasattr(self, 'moved_away'):
return
# and here code continues
What does the empty return mean?
return
exits the current function.So, here it will stop the execution & return
None
.It means it will
return None
. You could remove thereturn
and it would still returnNone
because all functions that don't specify a return value in python will by default returnNone
.In this particular case it means the code will go no further if the object has the attribute
'moved_away'
, without the return any code below would be evaluated even if theif
statement evaluated to True.So you can think of it as being similar to a break statement in a loop when you have a condition you want to exit the loop on, without the break the code would continue to be evaluated.