From the course: Python: Recursion

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Tail call optimization in Python

Tail call optimization in Python - Python Tutorial

From the course: Python: Recursion

Start my 1-month free trial

Tail call optimization in Python

- [Instructor] Some programming language, have a feature Called Tail Call Optimization, which enables a recursive algorithm to use much less memory than it otherwise would. By executing recursive function Calls in the current stack frame and returning the result rather than creating a new stack frame. Unfortunately, however, Python does not have this feature. It is nonetheless worth looking at how a Tail Optimization ready version of a recursive algorithm would look. So that you can understand the concept, deepen your understanding of recursion in general and know how to make use of Tail Call Optimization in languages, where it is possible. It can in fact be achieved in both using various hacks, but it's not genuinely recommended . When the only thing returned from a function, is a recursive call, It is referred to as Tail recursion. Let's look at two versions for our factorial function that we've been looking at…

Contents