Leveraging Python's Implicit "return None" Statements

Veröffentlicht am: 11 April 2017
auf dem Kanal: Real Python
17,094
261

https://dbader.org/python-tricks ► Write better and cleaner Python code with these bite-sized examples and tips

Python adds an implicit "return None" statement to the end of any function. Therefore, if a function doesn't specify a return value it returns None by default.

This means you can replace return None statements with bare return statements or even leave them out completely and still get the same behavior in your programs.

In this video tutorial I show you the rundown of how implicit return statements work in Python and how you can use them to make your code cleaner and more Pythonic.

I also cover the potential downsides of using this feature and how it can make your code harder to read in some cases.

On the one hand, you could argue that omitting an explicit return None statement makes the code more concise and therefore easier to read and understand. Subjectively you might also say it makes the code "prettier."

On the other hand, it might surprise some programmers that Python behaves this way. When it comes to writing clean and maintainable code, surprising behavior is rarely a good sign.

Watch the video for the full discussion.

FREE COURSE – "5 Thoughts on Mastering Python" https://dbader.org/python-mastery

SUBSCRIBE TO THIS CHANNEL: https://dbader.org/youtube

* *

► Python Developer MUGS, T-SHIRTS & MORE: https://nerdlettering.com

FREE Python Tutorials & News:
» Python Tutorials: https://dbader.org
» Python News on Twitter:   / @dbader_org  
» Weekly Tips for Pythonistas: https://dbader.org/newsletter
» Subscribe to this channel: https://dbader.org/youtube


Auf dieser Seite können Sie das Online-Video Leveraging Python's Implicit "return None" Statements mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Real Python 11 April 2017 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 17,094 Mal angesehen und es wurde von 261 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!