No, and it never will since Guido van Rossum prefers to be able to have proper tracebacks:

Tail Recursion Elimination (2009-04-22)

Final Words on Tail Calls (2009-04-27)

You can manually eliminate the recursion with a transformation like this:

>>> def trisum(n, csum):
...     while True:                     # Change recursion to a while loop
...         if n == 0:
...             return csum
...         n, csum = n - 1, csum + n   # Update parameters instead of tail recursion

>>> trisum(1000,0)
500500
Answer from John La Rooy on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › tail-recursion-in-python
Tail Recursion in Python - GeeksforGeeks
July 23, 2025 - This allows certain optimizations, known as tail call optimization (TCO), where the compiler or interpreter can reuse the current function's stack frame for the recursive call, effectively converting the recursion into iteration and preventing stack overflow errors. However, it's important to note that Python does not natively support tail call optimization.
Top answer
1 of 8
324

No, and it never will since Guido van Rossum prefers to be able to have proper tracebacks:

Tail Recursion Elimination (2009-04-22)

Final Words on Tail Calls (2009-04-27)

You can manually eliminate the recursion with a transformation like this:

>>> def trisum(n, csum):
...     while True:                     # Change recursion to a while loop
...         if n == 0:
...             return csum
...         n, csum = n - 1, csum + n   # Update parameters instead of tail recursion

>>> trisum(1000,0)
500500
2 of 8
232

I published a module performing tail-call optimization (handling both tail-recursion and continuation-passing style): https://github.com/baruchel/tco

Optimizing tail-recursion in Python

It has often been claimed that tail-recursion doesn't suit the Pythonic way of coding and that one shouldn't care about how to embed it in a loop. I don't want to argue with this point of view; sometimes however I like trying or implementing new ideas as tail-recursive functions rather than with loops for various reasons (focusing on the idea rather than on the process, having twenty short functions on my screen in the same time rather than only three "Pythonic" functions, working in an interactive session rather than editing my code, etc.).

Optimizing tail-recursion in Python is in fact quite easy. While it is said to be impossible or very tricky, I think it can be achieved with elegant, short and general solutions; I even think that most of these solutions don't use Python features otherwise than they should. Clean lambda expressions working along with very standard loops lead to quick, efficient and fully usable tools for implementing tail-recursion optimization.

As a personal convenience, I wrote a small module implementing such an optimization by two different ways. I would like to discuss here about my two main functions.

The clean way: modifying the Y combinator

The Y combinator is well known; it allows to use lambda functions in a recursive manner, but it doesn't allow by itself to embed recursive calls in a loop. Lambda calculus alone can't do such a thing. A slight change in the Y combinator however can protect the recursive call to be actually evaluated. Evaluation can thus be delayed.

Here is the famous expression for the Y combinator:

lambda f: (lambda x: x(x))(lambda y: f(lambda *args: y(y)(*args)))

With a very slight change, I could get:

lambda f: (lambda x: x(x))(lambda y: f(lambda *args: lambda: y(y)(*args)))

Instead of calling itself, the function f now returns a function performing the very same call, but since it returns it, the evaluation can be done later from outside.

My code is:

def bet(func):
    b = (lambda f: (lambda x: x(x))(lambda y:
          f(lambda *args: lambda: y(y)(*args))))(func)
    def wrapper(*args):
        out = b(*args)
        while callable(out):
            out = out()
        return out
    return wrapper

The function can be used in the following way; here are two examples with tail-recursive versions of factorial and Fibonacci:

>>> from recursion import *
>>> fac = bet( lambda f: lambda n, a: a if not n else f(n-1,a*n) )
>>> fac(5,1)
120
>>> fibo = bet( lambda f: lambda n,p,q: p if not n else f(n-1,q,p+q) )
>>> fibo(10,0,1)
55

Obviously recursion depth isn't an issue any longer:

>>> bet( lambda f: lambda n: 42 if not n else f(n-1) )(50000)
42

This is of course the single real purpose of the function.

Only one thing can't be done with this optimization: it can't be used with a tail-recursive function evaluating to another function (this comes from the fact that callable returned objects are all handled as further recursive calls with no distinction). Since I usually don't need such a feature, I am very happy with the code above. However, in order to provide a more general module, I thought a little more in order to find some workaround for this issue (see next section).

Concerning the speed of this process (which isn't the real issue however), it happens to be quite good; tail-recursive functions are even evaluated much quicker than with the following code using simpler expressions:

def bet1(func):
    def wrapper(*args):
        out = func(lambda *x: lambda: x)(*args)
        while callable(out):
            out = func(lambda *x: lambda: x)(*out())
        return out
    return wrapper

I think that evaluating one expression, even complicated, is much quicker than evaluating several simple expressions, which is the case in this second version. I didn't keep this new function in my module, and I see no circumstances where it could be used rather than the "official" one.

Continuation passing style with exceptions

Here is a more general function; it is able to handle all tail-recursive functions, including those returning other functions. Recursive calls are recognized from other return values by the use of exceptions. This solutions is slower than the previous one; a quicker code could probably be written by using some special values as "flags" being detected in the main loop, but I don't like the idea of using special values or internal keywords. There is some funny interpretation of using exceptions: if Python doesn't like tail-recursive calls, an exception should be raised when a tail-recursive call does occur, and the Pythonic way will be to catch the exception in order to find some clean solution, which is actually what happens here...

class _RecursiveCall(Exception):
  def __init__(self, *args):
    self.args = args
def _recursiveCallback(*args):
  raise _RecursiveCall(*args)
def bet0(func):
    def wrapper(*args):
        while True:
          try:
            return func(_recursiveCallback)(*args)
          except _RecursiveCall as e:
            args = e.args
    return wrapper

Now all functions can be used. In the following example, f(n) is evaluated to the identity function for any positive value of n:

>>> f = bet0( lambda f: lambda n: (lambda x: x) if not n else f(n-1) )
>>> f(5)(42)
42

Of course, it could be argued that exceptions are not intended to be used for intentionally redirecting the interpreter (as a kind of goto statement or probably rather a kind of continuation passing style), which I have to admit. But, again, I find funny the idea of using try with a single line being a return statement: we try to return something (normal behaviour) but we can't do it because of a recursive call occurring (exception).

Initial answer (2013-08-29).

I wrote a very small plugin for handling tail recursion. You may find it with my explanations there: https://groups.google.com/forum/?hl=fr#!topic/comp.lang.python/dIsnJ2BoBKs

It can embed a lambda function written with a tail recursion style in another function which will evaluate it as a loop.

The most interesting feature in this small function, in my humble opinion, is that the function doesn't rely on some dirty programming hack but on mere lambda calculus: the behaviour of the function is changed to another one when inserted in another lambda function which looks very like the Y combinator.

Discussions

Does python support Tail-Recursion
Python doesn't optimise tail-calls, so no. At least not right now. That said you're generally better-off with iterative solutions anyway unless the problem in question is either too complex to be effectively solved iteratively, or the recursion depth limit cannot reasonably ever be reached (eg. when traversing the filesystem, you're not going to run into a situation in practice where there would be directory trees much deeper than 30 nodes). For instance, there exists a really great iterative solution for the Fibonacci sequence: def fib(): a, b = 0, 1 while True: yield a a, b = b, a+b More on reddit.com
🌐 r/learnpython
7
2
October 6, 2021
Explicit tail calls - Ideas - Discussions on Python.org
There are good reasons for why Python doesn’t have automatic tail recursion elimination. (Implementation is difficult; developers need guarantees in order for it to make sense to write recursive algorithms.) But what about explicit tail calls? Compilers nowadays allow annotations for explicit ... More on discuss.python.org
🌐 discuss.python.org
9
July 11, 2025
Infinite recursion
In python version 3.13… I noticed the possibility of creating infinite recursion, that is, the stack does not overflow, this could be attributed to optimizing the “tail” recursion, but memory measurements showed that memory is consumed until it runs out. More on discuss.python.org
🌐 discuss.python.org
19
5
April 19, 2025
Tail call optimization in Python
https://neopythonic.blogspot.ca/2009/04/final-words-on-tail-calls.html More on reddit.com
🌐 r/Python
8
4
February 25, 2018
🌐
Chrispenner
chrispenner.ca › posts › python-tail-recursion
Tail Recursion In Python
Our decorator gets around that problem by continually entering and exiting a single call, so technically our function isn't actually recursive anymore and we avoid the limits. I tested out both versions, the normal version hits the tail-recursion limit at factorial(980) whereas the tail-recursive version will happily compute numbers as large as your computer can handle.
🌐
Invent with Python
inventwithpython.com › recursion › chapter8.html
Chapter 8 - Tail Call Optimization
Tail recursive functions require rearranging their code to make them suitable for the tail call optimization feature of the compiler or interpreter. However, not all compilers and interpreters offer tail call optimization as a feature. Notably, CPython (the Python interpreter downloaded from ...
🌐
Medium
helenrensiyu.medium.com › tail-recursion-in-python-2d8d839d5146
Tail Recursion in Python. The concept of recursion, which in the… | by Helen Ren | Medium
March 17, 2022 - A function is tail-recursive if it ends by returning the value of the recursive call — whereas if any further processing is done on the return value of the recursive call the function is non tail-recursive.
Find elsewhere
🌐
Python.org
discuss.python.org › ideas
Explicit tail calls - Ideas - Discussions on Python.org
July 11, 2025 - There are good reasons for why Python doesn’t have automatic tail recursion elimination. (Implementation is difficult; developers need guarantees in order for it to make sense to write recursive algorithms.) But what about explicit tail calls? Compilers nowadays allow annotations for explicit tail calls, which enable things like A new tail-calling interpreter for significantly better interpreter performance .
🌐
Hacker News
news.ycombinator.com › item
Did Python ever get tail recursion? There was a big controversy years ago. Guido... | Hacker News
August 12, 2025 - Enthusiasm for tail recursion comes mostly from LISP and LISP-adjacent people - those who learned to program from SICP.[1] This is neither good nor bad. Even MIT doesn't use SICP any more, though · These are mostly of historical interest now, but at one time, knowing those defined a real computer ...
🌐
PyPI
pypi.org › project › tail-recursive
tail-recursive · PyPI
This feature will resolve tail calls passed as parameters to other tail calls.
🌐
Sagnibak
sagnibak.github.io › blog › python-is-haskell-tail-recursion
Python is the Haskell You Never Knew You Had: Tail Call Optimization
August 16, 2020 - The decorator should be a higher-order function which takes in a function fn and returns an inner function which when called, calls fn, but with some scaffolding. fn must follow a specific form: it must return something which instructs the inner function (often called the trampoline function) whether it wants to recurse or return. For this, we need two classes representing the two cases: fn should return an instance of TailCall when it wants to make a tail recursive call, and it should feed the arguments of the next call into the instance.
🌐
Google Groups
groups.google.com › g › sage-flame › c › hFB33NeMTzI
Tail recursion optimization in Python
Results: - a @tail_recursive decorated function does not have its tail recursion limited by the 999 stack frames (or whatever bound one configures in python) - for both "factorial" and for "silly odd/even test", the decorated version is considerably faster for calls requiring depth 900 - in all cases, the iterative version is much faster - for small depths, the undecorated version is quite a bit faster - indiscriminate use of the decorator invalidates your code.
🌐
Lobsters
lobste.rs › s › ui5fzs › cpython_tail_call_interpreter_merged_for
CPython tail-call interpreter merged for Python 3.14, a 10% speedup in benchmarks | Lobsters
February 7, 2025 - @apg is saying that it's rare to see such tail recursion in Python (after all, it's not super common for Python functions to call themselves at all; let alone as a tail call).
🌐
Quora
quora.com › Why-cant-Python-handle-tail-call-recursion
Why can't Python handle tail-call recursion? - Quora
Answer: It can/could. It prefers not to. The reasoning is outlined here and here. The underlying reason is that, in python, you have loops/generators and recursion. You use loops for iteration and recursion for recursion. Making the distinction means that, if you’re doing recursion and somethin...
🌐
Medium
medium.com › @giorgio.zoppi › tail-recursion-optimization-from-stack-frames-to-python-3-14-a76ba24fb3d1
Tail Recursion Optimization: From Stack Frames to Python 3.14 | by Giorgio Zoppi | Medium
September 27, 2025 - Understanding stack frames and tail calls is key to efficient recursion · Scala provides native support with @tailrec. Python 3.14 introduces tail-call-based opcode dispatch, improving recursion performance.
🌐
Medium
medium.com › data-science › what-is-tail-recursion-elimination-or-why-functional-programming-can-be-awesome-43091d76915e
How Functional Programming can be Awesome: Tail Recursion Elimination | by Luciano Strika | TDS Archive | Medium
August 24, 2018 - Tail Recursion Elimination is a very interesting feature available in Functional Programming languages, like Haskell and Scala. It makes recursive function calls almost as fast as looping. In my latest article about Functional Programming features ...
🌐
DEV Community
dev.to › apoorvtyagi › tail-recursion-in-python-2og0
Tail recursion in python 🐍 - DEV Community
October 19, 2020 - But the real question is can we ... recursion with a transformation which we will see in the next section. Recursive tail calls can be replaced by jumps....
🌐
Python.org
discuss.python.org › python help
Infinite recursion - Python Help - Discussions on Python.org
April 19, 2025 - In python version 3.13… I noticed the possibility of creating infinite recursion, that is, the stack does not overflow, this could be attributed to optimizing the “tail” recursion, but memory measurements showed that memory is consumed until it runs out.
🌐
Medium
medium.com › @tssovi › tail-recursion-and-head-recursion-d9aeb8478b12
Tail Recursion and Head Recursion | by Tusamma Sal Sabil | Medium
March 24, 2020 - A recursive function is tail recursive when recursive call is the last thing executed by the function. For example the following Python function factorial() is tail recursive.
🌐
C# Corner
c-sharpcorner.com › article › what-is-tail-recursion-and-how-to-use-it-in-functional-programming
What is Tail Recursion and its Benefits in Functional Programming
October 6, 2025 - Tail recursion reuses the same memory space instead of creating new stack frames every time. This makes your recursive function faster, safer, and memory-efficient. Although Python doesn’t perform tail call optimization (TCO) by default like ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › recursion-in-python
Recursion in Python - GeeksforGeeks
The main difference between them is related to what happens after recursive call. Tail Recursion: The recursive call is the last thing the function does, so nothing happens after it returns.
Published: May 19, 2026