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
๐ŸŒ
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.
๐ŸŒ
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.
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
Tail recursion in Python
lru_cache, from the functools library ยท The example given in the docs [0] is: More on news.ycombinator.com
๐ŸŒ news.ycombinator.com
80
193
March 18, 2018
Using python to implement the tail recursion function - Stack Overflow
Note that python does not have tail call optimization, so forcing code to be tail recursive is generally a waste. Do you really need this restriction (e.g. More on stackoverflow.com
๐ŸŒ stackoverflow.com
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
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.

๐ŸŒ
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.
๐ŸŒ
Kylem
kylem.net โ€บ programming โ€บ tailcall.html
Tail call recursion in Python - Kyle Miller
Our running example is going to be the factorial function (a classic), written with an accumulator argument so that its recursive call is a tail call: def fact(n, r=1) : if n <= 1 : return r else : return fact(n-1, n*r) If n is too large, then this recursive function will overflow the stack, despite the fact that Python can deal with really big integers.
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
The Trojan
apoorvtyagi.tech โ€บ tail-recursion-in-python
Tail recursion in python - The Trojan
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....
๐ŸŒ
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 ...
๐ŸŒ
CodinGeek
codingeek.com โ€บ home โ€บ recursion in python
Python Recursion with Example and tail recursion | Codingeek
April 5, 2021 - It is sometimes hard to follow through with the logic behind the recursion. Tail-recursion can be defined as a special kind of recursion in which the last statement of a function is a recursive call.
๐ŸŒ
Hacker News
news.ycombinator.com โ€บ item
Tail recursion in Python | Hacker News
March 18, 2018 - lru_cache, from the functools library ยท The example given in the docs [0] is:
๐ŸŒ
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....
๐ŸŒ
Winged
winged.ch โ€บ tail_recursion_in_python
Tail recursion in python - Winged.ch
May 9, 2016 - @tail_callable def fib(a, b): print(a) return tail_call(fib, b, a + b) You see the decorator, and the call to our helper function that wraps the actual recursion.
๐ŸŒ
GitHub
github.com โ€บ baruchel โ€บ tco
GitHub - baruchel/tco: Tail Call Optimization for Python ยท GitHub
A module for performing tail-call optimization in Python code. The module allows a coder to write tail-recursive functions as well as using continuation-passing style in his/her code without having the size of the execution stack increasing.
๐ŸŒ
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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ tail-recursion
Tail Recursion - GeeksforGeeks
It is a non-tail-recursive function. Although it looks like a tail recursive at first look. If we take a closer look, we can see that the value returned by fact(n-1) is used in fact(n).
Published: January 20, 2026
๐ŸŒ
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.
๐ŸŒ
GitConnected
levelup.gitconnected.com โ€บ functional-programming-and-tail-recursion-in-python-01e0fbc97613
Functional Programming and Tail Recursion in Python | by Manmohan Krishna | Level Up Coding
May 28, 2024 - Pythonโ€™s Higher Order Functions(HOFs) Tail Recursion and Continuation Passing Style(CPS) Tail recursion is a form of recursion where the recursive call is the last operation in the function. This allows for optimization...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ tail-recursion-in-python-without-introspection
Tail Recursion in Python Without Introspection - GeeksforGeeks
July 23, 2025 - To overcome this, we can convert the recursive structure of the function into an iterative structure using Python decorators. ... # class to define our own exception class Recurse(Exception): def __init__(self, *args: object) -> None: super(Recurse, self).__init__() self.args = args # function to simulate the # tail-recursive call def recurse_sim(*args): raise Recurse(*args) # decorator function to convert # recursive -> iterative def iterative_recursion(fn): def wrapper(*args): while 1: try: return fn(*args) except Recurse as exc: args = exc.args return wrapper # tail recursive function # implementation @iterative_recursion def count_pseudo_recursive(n): if n < 0: return print("Counting", n) return recurse_sim(n - 1) # function call to start the # tail recursion count_pseudo_recursive(3)