Recursion in Python (Summary)
That concludes your journey through recursion, a programming technique in which a function calls itself. Recursion isn’t by any means appropriate for every task. But some programming problems virtually cry out for it. In those situations, it’s a great technique to have at your disposal.
In this video course, you learned:
- What it means for a function to call itself recursively
- When recursion might be your best best for solving a problem
- How you can implement recursion for various use cases in Python
You also saw several examples of recursive algorithms and compared them to corresponding non-recursive solutions.
You should now be in a good position to recognize when recursion is called for and be ready to use it confidently when it’s needed!
For further investigation, check out:
- Sorting Algorithms in Python
- Introduction to Sorting Algorithms in Python
- Draw the Mandelbrot Set in Python
- Real Python Episode 124: Exploring Recursion in Python With Al Sweigart
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
00:00 In the previous lesson, I showed you the Quicksort algorithm. In this lesson, I’ll summarize the course and point you at some places for further investigation.
00:10 A recursive function is one that calls itself. The call stack creates a separate space for each invocation of a function, so functions can call themselves without stomping on their own data.
00:22 Recursive algorithms are commonly used for traversing tree-like structures, sorting, fractals, and functional programming languages.
00:34 If you want to learn more about sorting in Python, this content is available in both tutorial and course format. If you’d like to use recursion to play with fractals, this tutorial might be interesting for you. And finally, Al Sweigart wrote a book on recursion, and Christopher Bailey spoke with him in the Real Python Podcast Episode 124.
00:57 Thanks for your attention. I hope you enjoyed the course. Was that a meteor? Hmm. Time to buy a lottery ticket.
Become a Member to join the conversation.