Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Benefits of using return when there are no values expected from the function

Hi! Is there any benefits of using 'return' at the end of a python function if the function doesn't return any values? Thank you in advance!

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

Hey Yahya Alshwaily, great question.

There is an implicit return None at the end of every function or method. However, a simple return helps in readability.

When scanning code, a return is expected so it helps to see it. As the Zen of Python says “explicit is better than implicit”

The one exception is the __init__ method. It is never expected to return anything so a return is not used. The __init__ method operates on an existing instance referenced by self.

The following are functionally equivalent:

return None
return 
# no return

Post back if you need more help. Good luck!!!