Using the Python return Statement Effectively
The Pythonreturn statement is a key component offunctions andmethods. You can use thereturn statement to make your functions send Python objects back to the caller code. These objects are known as the function’sreturn value. You can use them to perform further computation in your programs.
Using thereturn statement effectively is a core skill if you want to code custom functions that arePythonic and robust.
In this course, you’ll learn:
- How to use thePython
returnstatement in your functions - How to returnsingle ormultiple values from your functions
- Whatbest practices to observe when using
returnstatements - How to structure moreadvanced return statements
What’s Included:
- 22 Lessons
- Video Subtitles and Full Transcripts
- 2 Downloadable Resources
- Accompanying Text-Based Tutorial
- Interactive Quiz to Check Your Progress
- Q&A With Python Experts: Ask a Question
- Certificate of Completion
Downloadable Resources:
Related Learning Paths:
Syntax for Writing return Statements in Python
6 Lessons 22m
Best Practices for Using return in Python
9 Lessons 39m
- 1. Returning None Explicitly02:53
- 2. Remembering to Return and Keeping It Readable04:11
- 3. Returning Values vs Modifying Global Variables05:08
- 4. Using return Statements With Conditionals05:49
- 5. Returning Boolean Values04:48
- 6. Returning Expressions With Boolean Operators05:28
- 7. Using return to Short-Circuit Your Loops04:13
- 8. Recognizing and Avoiding Dead Code01:56
- 9. Returning Multiple Values With namedtuple04:34
Advanced Uses of return in Python
7 Lessons 29m
- 1. Using Functions as Return Values: Closures05:13
- 2. Taking and Returning Functions With Decorators06:43
- 3. Returning User-Defined Objects With Factory Patterns04:51
- 4. Using return With try and finally Blocks03:53
- 5. Using return vs yield in Generator Functions03:46
- 6. Using the Python return Statement Effectively (Summary)00:52
- 7. The Python return Statement (Quiz)04:00
AboutHoward Francis
Howard is an avid Pythonista and records video courses for Real Python. He has been teaching beginning programming at the college level for over 20 years in C++, Java, C#, and most recently Python.
» More about HowardParticipant Comments
alnah
This course was outstanding! It was well-structured, clear, and practical. I especially appreciated the sections on closures, decorators/wrappers, and factories. It provides a good introduction to understanding generators as well. The best practices part was very great! Please do that for functions in Python as well!
Shubha
Great Course! Learnt a lot. Thank you.














