# Recursion in Python: An Introduction

DevFeed: [Recursion in Python: An Introduction](<https://devfeed.tech/articles/recursion-in-python-an-introduction-110731.md>)

Original publisher: [Read original article](<https://realpython.com/python-recursion/>)

Author: John Sturtz

Published: 2026-11-01T14:00:00Z

Content type: article

Language: en

Sources: [Real Python](<https://devfeed.tech/sources/real-python.md>)

Topics: [Python](<https://devfeed.tech/topics/python.md>), [execution](<https://devfeed.tech/topics/execution.md>), [Functional programming](<https://devfeed.tech/topics/functional-programming.md>)

Tags: [algorithm](<https://devfeed.tech/tags/algorithm.md>), [algorithms](<https://devfeed.tech/tags/algorithms.md>), [c](<https://devfeed.tech/tags/c.md>), [code](<https://devfeed.tech/tags/code.md>), [comparison](<https://devfeed.tech/tags/comparison.md>), [data-structures](<https://devfeed.tech/tags/data-structures.md>), [divide-and-conquer](<https://devfeed.tech/tags/divide-and-conquer.md>), [enumerate](<https://devfeed.tech/tags/enumerate.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [python](<https://devfeed.tech/tags/python.md>), [recursion](<https://devfeed.tech/tags/recursion.md>)

## AI overview

Python recursion is a function calling itself; a useful recursive function has directly solvable base cases and calls that move toward them, or it can hit Python's recursion limit and raise `RecursionError`. The tutorial compares recursive and iterative approaches using countdown, factorial, nested-list traversal, and palindrome examples. For factorial, recursion closely mirrors the mathematical definition, but iteration is similarly straightforward; the sample timings vary by machine and show `math.factorial()` much faster than the Python implementations. For nested lists, recursion is more concise than an iterative version that tracks parent lists and indexes on a stack. The tutorial also shows Quicksort using median-of-three pivot selection and recursive partitions, while noting that its sample implementation creates three partition lists in separate passes and is not the most efficient. It recommends weighing readability, problem structure, memory use, and execution speed.

## Source excerpt

Get to grips with Python recursion: what it is, how it works, when to reach for it, and how recursive and iterative solutions compare.