René's URL Explorer Experiment


Title: Recursion in Python: An Introduction – Real Python

Open Graph Title: Recursion in Python: An Introduction – Real Python

Description: In this tutorial, you'll learn about recursion in Python. You'll see what recursion is, how it works in Python, and under what circumstances you should use it. You'll finish by exploring several examples of problems that can be solved both recursively and non-recursively.

Open Graph Description: In this tutorial, you'll learn about recursion in Python. You'll see what recursion is, how it works in Python, and under what circumstances you should use it. You'll finish by exploring several examples of problems that can be solved both recursively and non-recursively.

Mail addresses
?subject=Python article for you&body=Recursion in Python: An Introduction on Real Python https://realpython.com/python-recursion/

Opengraph URL: https://realpython.com/python-recursion/

X: @realpython

direct link

Domain: realpython.com


Hey, it has json ld scripts:
{
  "@context": "http://schema.org",
  "@type": "Article",
  "headline": "Recursion in Python: An Introduction",
  "image": {
    "@type": "ImageObject",
    "url": "https://files.realpython.com/media/TUT20-Recursion-in-Python_Watermarked.692052217920.jpg",
    "width": 1920,
    "height": 1080
  },
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://realpython.com/python-recursion/",
    "lastReviewed": "2023-10-21",
    "author": {
      "@type": "Person",
      "name": "John Sturtz",
      "image": "https://realpython.com/cdn-cgi/image/width=1920,height=1920,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/real-python-logo-square.28474fda9228_1.146e987bf77c.png",
      "url": "https://realpython.com/team/jsturtz/",
      "affiliation": {
        "@type": "Organization",
        "@id": "https://realpython.com/#organization",
        "name": "Real Python",
        "url": "https://realpython.com",
        "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
      }
    },
    "reviewedBy": [
      {
        "@type": "Person",
        "name": "Aldren Santos",
        "image": "https://realpython.com/cdn-cgi/image/width=500,height=500,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Aldren_Santos_Real_Python.6b0861d8b841.png",
        "url": "https://realpython.com/team/asantos/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Bartosz Zaczy\u0144ski",
        "image": "https://realpython.com/cdn-cgi/image/width=1694,height=1694,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/coders_lab_2109368.259b1599fbee.jpg",
        "url": "https://realpython.com/team/bzaczynski/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Joanna Jablonski",
        "image": "https://realpython.com/cdn-cgi/image/width=800,height=800,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/jjablonksi-avatar.e37c4f83308e.jpg",
        "url": "https://realpython.com/team/jjablonski/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      },
      {
        "@type": "Person",
        "name": "Jacob Schmitt",
        "image": "https://realpython.com/cdn-cgi/image/width=400,height=400,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/profile-small_js.2f4d0d8da1ca.jpg",
        "url": "https://realpython.com/team/jschmitt/",
        "affiliation": {
          "@type": "Organization",
          "@id": "https://realpython.com/#organization",
          "name": "Real Python",
          "url": "https://realpython.com",
          "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
        }
      }
    ]
  },
  "datePublished": "2021-05-10T14:00:00+00:00",
  "dateModified": "2023-10-21T03:00:39.524633+00:00",
  "publisher": {
    "@type": "Organization",
    "@id": "https://realpython.com/#organization",
    "name": "Real Python",
    "url": "https://realpython.com",
    "logo": {
      "@type": "ImageObject",
      "url": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png",
      "width": 512,
      "height": 512
    },
    "description": "Real Python is a leading provider of online Python education and one of the largest language-specific online communities for software developers. It publishes high-quality learning resources, such as tutorials, books, and courses to an audience of millions of developers, data scientists, and machine learning engineers each month.",
    "slogan": "Become a Python Expert",
    "email": "info@realpython.com",
    "sameAs": [
      "https://github.com/realpython",
      "https://www.youtube.com/realpython",
      "https://twitter.com/realpython",
      "https://x.com/realpython",
      "https://www.linkedin.com/company/realpython-com/",
      "https://www.facebook.com/learnrealpython",
      "https://www.instagram.com/realpython",
      "https://www.tiktok.com/@realpython.com"
    ]
  },
  "author": {
    "@type": "Person",
    "name": "John Sturtz",
    "image": "https://realpython.com/cdn-cgi/image/width=1920,height=1920,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/real-python-logo-square.28474fda9228_1.146e987bf77c.png",
    "url": "https://realpython.com/team/jsturtz/",
    "affiliation": {
      "@type": "Organization",
      "@id": "https://realpython.com/#organization",
      "name": "Real Python",
      "url": "https://realpython.com",
      "logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
    }
  },
  "description": "In this tutorial, you'll learn about recursion in Python. You'll see what recursion is, how it works in Python, and under what circumstances you should use it. You'll finish by exploring several examples of problems that can be solved both recursively and non-recursively."
}

authorReal Python
twitter:cardsummary_large_image
twitter:imagehttps://files.realpython.com/media/TUT20-Recursion-in-Python_Watermarked.692052217920.jpg
og:imagehttps://files.realpython.com/media/TUT20-Recursion-in-Python_Watermarked.692052217920.jpg
twitter:creator@realpython
og:typearticle

Links:

https://realpython.com/
Start Herehttps://realpython.com/start-here/
Learn Python https://realpython.com/python-recursion/
Python Tutorials →In-depth articles and video courseshttps://realpython.com/search?kind=article&kind=course&order=newest
Learning Paths →Guided study plans for accelerated learninghttps://realpython.com/learning-paths/
Quizzes & Exercises →Check your learning progresshttps://realpython.com/quizzes/
Browse Topics →Focus on a specific area or skill levelhttps://realpython.com/tutorials/all/
Community Chat →Learn with other Pythonistashttps://realpython.com/community/
Office Hours →Live Q&A calls with Python expertshttps://realpython.com/office-hours/
Podcast →Hear what’s new in the world of Pythonhttps://realpython.com/podcasts/rpp/
Books →Round out your knowledge and learn offlinehttps://realpython.com/products/books/
Reference →Concise definitions for common Python termshttps://realpython.com/ref/
Code Mentor →BetaPersonalized code assistance & learning toolshttps://realpython.com/mentor/
Unlock All Content →https://realpython.com/account/join/
More https://realpython.com/python-recursion/
Learner Storieshttps://realpython.com/learner-stories/
Python Newsletterhttps://realpython.com/newsletter/
Python Job Boardhttps://www.pythonjobshq.com
Meet the Teamhttps://realpython.com/team/
Become a Tutorial Writerhttps://realpython.com/write-for-us/
Become a Video Instructorhttps://realpython.com/become-an-instructor/
Searchhttps://realpython.com/search
https://realpython.com/search
Joinhttps://realpython.com/account/join/
Sign‑Inhttps://realpython.com/account/login/?next=%2Fpython-recursion%2F
Browse Topicshttps://realpython.com/tutorials/all/
Guided Learning Pathshttps://realpython.com/learning-paths/
Basicshttps://realpython.com/search?level=basics
Intermediatehttps://realpython.com/search?level=intermediate
Advancedhttps://realpython.com/search?level=advanced
aihttps://realpython.com/tutorials/ai/
algorithmshttps://realpython.com/tutorials/algorithms/
apihttps://realpython.com/tutorials/api/
best-practiceshttps://realpython.com/tutorials/best-practices/
careerhttps://realpython.com/tutorials/career/
communityhttps://realpython.com/tutorials/community/
databaseshttps://realpython.com/tutorials/databases/
data-sciencehttps://realpython.com/tutorials/data-science/
data-structureshttps://realpython.com/tutorials/data-structures/
data-vizhttps://realpython.com/tutorials/data-viz/
devopshttps://realpython.com/tutorials/devops/
djangohttps://realpython.com/tutorials/django/
dockerhttps://realpython.com/tutorials/docker/
editorshttps://realpython.com/tutorials/editors/
flaskhttps://realpython.com/tutorials/flask/
front-endhttps://realpython.com/tutorials/front-end/
gamedevhttps://realpython.com/tutorials/gamedev/
guihttps://realpython.com/tutorials/gui/
machine-learninghttps://realpython.com/tutorials/machine-learning/
newshttps://realpython.com/tutorials/news/
numpyhttps://realpython.com/tutorials/numpy/
projectshttps://realpython.com/tutorials/projects/
pythonhttps://realpython.com/tutorials/python/
stdlibhttps://realpython.com/tutorials/stdlib/
testinghttps://realpython.com/tutorials/testing/
toolshttps://realpython.com/tutorials/tools/
web-devhttps://realpython.com/tutorials/web-dev/
web-scrapinghttps://realpython.com/tutorials/web-scraping/
Table of Contentshttps://realpython.com/python-recursion/#toc
What Is Recursion?https://realpython.com/python-recursion/#what-is-recursion
Why Use Recursion?https://realpython.com/python-recursion/#why-use-recursion
Recursion in Pythonhttps://realpython.com/python-recursion/#recursion-in-python
Get Started: Count Down to Zerohttps://realpython.com/python-recursion/#get-started-count-down-to-zero
Calculate Factorialhttps://realpython.com/python-recursion/#calculate-factorial
Define a Python Factorial Functionhttps://realpython.com/python-recursion/#define-a-python-factorial-function
Speed Comparison of Factorial Implementationshttps://realpython.com/python-recursion/#speed-comparison-of-factorial-implementations
Traverse a Nested Listhttps://realpython.com/python-recursion/#traverse-a-nested-list
Traverse a Nested List Recursivelyhttps://realpython.com/python-recursion/#traverse-a-nested-list-recursively
Traverse a Nested List Non-Recursivelyhttps://realpython.com/python-recursion/#traverse-a-nested-list-non-recursively
Detect Palindromeshttps://realpython.com/python-recursion/#detect-palindromes
Sort With Quicksorthttps://realpython.com/python-recursion/#sort-with-quicksort
Choosing the Pivot Itemhttps://realpython.com/python-recursion/#choosing-the-pivot-item
Implementing the Partitioninghttps://realpython.com/python-recursion/#implementing-the-partitioning
Using the Quicksort Implementationhttps://realpython.com/python-recursion/#using-the-quicksort-implementation
Conclusionhttps://realpython.com/python-recursion/#conclusion
https://realpython.com/feedback/survey/article/python-recursion/liked/?from=article-sidebar
https://realpython.com/feedback/survey/article/python-recursion/disliked/?from=article-sidebar
Recursion in Pythonhttps://realpython.com/courses/python-recursion/
John Sturtzhttps://realpython.com/python-recursion/#author
https://realpython.com/python-recursion/#reader-comments
intermediatehttps://realpython.com/tutorials/intermediate/
algorithmshttps://realpython.com/tutorials/algorithms/
pythonhttps://realpython.com/tutorials/python/
What Is Recursion?https://realpython.com/python-recursion/#what-is-recursion
Why Use Recursion?https://realpython.com/python-recursion/#why-use-recursion
Recursion in Pythonhttps://realpython.com/python-recursion/#recursion-in-python
Get Started: Count Down to Zerohttps://realpython.com/python-recursion/#get-started-count-down-to-zero
Calculate Factorialhttps://realpython.com/python-recursion/#calculate-factorial
Define a Python Factorial Functionhttps://realpython.com/python-recursion/#define-a-python-factorial-function
Speed Comparison of Factorial Implementationshttps://realpython.com/python-recursion/#speed-comparison-of-factorial-implementations
Traverse a Nested Listhttps://realpython.com/python-recursion/#traverse-a-nested-list
Traverse a Nested List Recursivelyhttps://realpython.com/python-recursion/#traverse-a-nested-list-recursively
Traverse a Nested List Non-Recursivelyhttps://realpython.com/python-recursion/#traverse-a-nested-list-non-recursively
Detect Palindromeshttps://realpython.com/python-recursion/#detect-palindromes
Sort With Quicksorthttps://realpython.com/python-recursion/#sort-with-quicksort
Choosing the Pivot Itemhttps://realpython.com/python-recursion/#choosing-the-pivot-item
Implementing the Partitioninghttps://realpython.com/python-recursion/#implementing-the-partitioning
Using the Quicksort Implementationhttps://realpython.com/python-recursion/#using-the-quicksort-implementation
Conclusionhttps://realpython.com/python-recursion/#conclusion
Remove adshttps://realpython.com/account/join/
Recursion in Pythonhttps://realpython.com/courses/python-recursion/
functions in Pythonhttps://realpython.com/defining-your-own-python-function/
https://realpython.com/quizzes/python-recursion/
Recursion in Python: An Introductionhttps://realpython.com/quizzes/python-recursion/
Get a sample chapter from Python Basics: A Practical Introduction to Python 3https://realpython.com/bonus/python-basics-sample-free-chapter/
https://realpython.com/python-recursion/#what-is-recursion
Dictionary.com:https://www.dictionary.com/browse/recursion
Wiktionary:https://en.wiktionary.org/wiki/recursion
The Free Dictionary:https://www.thefreedictionary.com/recursion
https://files.realpython.com/media/jsturtz-ancestors.9f0adeb014ef.png
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-recursion/#why-use-recursion
tree-like data structureshttps://en.wikipedia.org/wiki/Tree_(data_structure)
https://realpython.com/python-recursion/#recursion-in-python
local namespacehttps://realpython.com/python-namespaces-scope/
collidehttps://en.wikipedia.org/wiki/Name_collision
tracebackhttps://realpython.com/python-traceback/
exceptionhttps://realpython.com/python-exceptions/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-recursion/#get-started-count-down-to-zero
https://realpython.com/python-recursion/#calculate-factorial
factorialhttps://en.wikipedia.org/wiki/Factorial
https://files.realpython.com/media/jsturtz-factorial-defn.b3cd3711a627.png
https://files.realpython.com/media/jsturtz-recursive-factorial-defn.32f2c2a3048a.png
https://files.realpython.com/media/jsturtz-factorial-example.496c01139673.png
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-recursion/#define-a-python-factorial-function
print()https://realpython.com/python-print/
forhttps://realpython.com/python-for-loop/
reduce()https://realpython.com/python-reduce-function/
importhttps://realpython.com/python-import/
https://realpython.com/python-recursion/#speed-comparison-of-factorial-implementations
timeit()https://docs.python.org/3/library/timeit.html#timeit.timeit
math modulehttps://realpython.com/python-math-module/
Chttps://en.wikipedia.org/wiki/C_(programming_language)
Python Bindings: Calling C or C++ From Pythonhttps://realpython.com/python-bindings-overview/
Building a Python C Extension Modulehttps://realpython.com/build-python-c-extension-module/
C for Python Programmershttps://realpython.com/c-for-python-programmers/
Your Guide to the CPython Source Codehttps://realpython.com/cpython-source-code-guide/
CPython Internals bookhttps://realpython.com/products/cpython-internals-book/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-recursion/#traverse-a-nested-list
listhttps://realpython.com/python-list/
https://files.realpython.com/media/jsturtz-nested-list.20eb8fe32366.png
https://realpython.com/python-recursion/#traverse-a-nested-list-recursively
isinstance()https://realpython.com/what-does-isinstance-do-in-python/
print()https://realpython.com/python-print/
returnhttps://realpython.com/python-return-statement/
dictionaryhttps://realpython.com/python-dicts/
tuplehttps://realpython.com/python-tuple/
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-recursion/#traverse-a-nested-list-non-recursively
stackhttps://realpython.com/how-to-implement-python-stack/
https://files.realpython.com/media/jsturtz-traversal-comparison.930c512e5fd6.png
https://realpython.com/python-recursion/#detect-palindromes
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-recursion/#sort-with-quicksort
Quicksort algorithmhttps://realpython.com/sorting-algorithms-python/#the-quicksort-algorithm-in-python
divide-and-conquer algorithmhttps://en.wikipedia.org/wiki/Divide-and-conquer_algorithm
https://realpython.com/python-recursion/#choosing-the-pivot-item
https://files.realpython.com/media/jsturtz-optimal-pivot.93e52ac803a8.png
https://files.realpython.com/media/jsturtz-suboptimal-pivot.546d83e040c3.png
https://realpython.com/python-recursion/#implementing-the-partitioning
Remove adshttps://realpython.com/account/join/
https://realpython.com/python-recursion/#using-the-quicksort-implementation
https://files.realpython.com/media/jsturtz-qsort.8fac5b768da0.png
https://realpython.com/python-recursion/#conclusion
https://realpython.com/quizzes/python-recursion/
Recursion in Python: An Introductionhttps://realpython.com/quizzes/python-recursion/
Thinking Recursively in Pythonhttps://realpython.com/python-thinking-recursively/
https://realpython.com/feedback/survey/article/python-recursion/liked/?from=article-footer
https://realpython.com/feedback/survey/article/python-recursion/disliked/?from=article-footer
Recursion in Pythonhttps://realpython.com/courses/python-recursion/
https://realpython.com/team/jsturtz/
» More about Johnhttps://realpython.com/team/jsturtz/
https://realpython.com/team/asantos/
Aldrenhttps://realpython.com/team/asantos/
https://realpython.com/team/bzaczynski/
Bartoszhttps://realpython.com/team/bzaczynski/
https://realpython.com/team/jjablonski/
Joannahttps://realpython.com/team/jjablonski/
https://realpython.com/team/jschmitt/
Jacobhttps://realpython.com/team/jschmitt/
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=python-recursion
Level Up Your Python Skills »https://realpython.com/account/join/?utm_source=rp_article_footer&utm_content=python-recursion
https://realpython.com/feedback/survey/article/python-recursion/liked/?from=article-comments
https://realpython.com/feedback/survey/article/python-recursion/disliked/?from=article-comments
LinkedInhttps://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Frealpython.com%2Fpython-recursion%2F
Twitterhttps://twitter.com/intent/tweet/?text=Interesting%20Python%20article%20on%20%40realpython%3A%20Recursion%20in%20Python%3A%20An%20Introduction&url=https%3A%2F%2Frealpython.com%2Fpython-recursion%2F
Blueskyhttps://bsky.app/intent/compose?text=Interesting%20Python%20article%20on%20%40realpython.com%3A%20Recursion%20in%20Python%3A%20An%20Introduction%20https%3A%2F%2Frealpython.com%2Fpython-recursion%2F
Facebookhttps://facebook.com/sharer/sharer.php?u=https%3A%2F%2Frealpython.com%2Fpython-recursion%2F
Get tips for asking good questionshttps://realpython.com/python-beginner-tips/#tip-9-ask-good-questions
get answers to common questions in our support portalhttps://support.realpython.com
Real Python Community Chathttps://realpython.com/community/
“Office Hours” Live Q&A Sessionhttps://realpython.com/office-hours/
intermediatehttps://realpython.com/tutorials/intermediate/
algorithmshttps://realpython.com/tutorials/algorithms/
pythonhttps://realpython.com/tutorials/python/
Recursion in Pythonhttps://realpython.com/courses/python-recursion/
Sorting Algorithms in Pythonhttps://realpython.com/sorting-algorithms-python/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-recursion
Object-Oriented Programming (OOP) in Pythonhttps://realpython.com/python3-object-oriented-programming/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-recursion
How to Use Python Lambda Functionshttps://realpython.com/python-lambda/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-recursion
Python Inner Functions: What Are They Good For?https://realpython.com/inner-functions-what-are-they-good-for/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-recursion
Thinking Recursively in Pythonhttps://realpython.com/python-thinking-recursively/?utm_source=realpython&utm_medium=web&utm_campaign=related-post&utm_content=python-recursion
https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fpython-recursion%2F
Continue »https://realpython.com/account/signup/?intent=continue_reading&utm_source=rp&utm_medium=web&utm_campaign=rwn&utm_content=v1&next=%2Fpython-recursion%2F
Sign-Inhttps://realpython.com/account/login/?next=/python-recursion/
Start Herehttps://realpython.com/start-here/
Learning Resourceshttps://realpython.com/search
Code Mentorhttps://realpython.com/mentor/
Python Referencehttps://realpython.com/ref/
Python Cheat Sheethttps://realpython.com/cheatsheets/python/
Support Centerhttps://support.realpython.com/
Learning Pathshttps://realpython.com/learning-paths/
Quizzes & Exerciseshttps://realpython.com/quizzes/
Browse Topicshttps://realpython.com/tutorials/all/
Live Courseshttps://realpython.com/live/
Bookshttps://realpython.com/books/
Podcasthttps://realpython.com/podcasts/rpp/
Newsletterhttps://realpython.com/newsletter/
Community Chathttps://realpython.com/community/
Office Hourshttps://realpython.com/office-hours/
Learner Storieshttps://realpython.com/learner-stories/
Plans & Pricinghttps://realpython.com/account/join/
Team Planshttps://realpython.com/account/join-team/
For Businesshttps://realpython.com/account/join-team/inquiry/
For Schoolshttps://realpython.com/account/join-team/education-inquiry/
Reviewshttps://realpython.com/learner-stories/
About Ushttps://realpython.com/about/
Teamhttps://realpython.com/team/
Mission & Valueshttps://realpython.com/mission/
Editorial Guidelineshttps://realpython.com/editorial-guidelines/
Sponsorshipshttps://realpython.com/sponsorships/
Careershttps://realpython.workable.com
Press Kithttps://realpython.com/media-kit/
Merchhttps://realpython.com/merch
https://www.youtube.com/realpython
https://x.com/realpython
https://www.linkedin.com/company/realpython-com
https://www.facebook.com/LearnRealPython
https://github.com/realpython/
Privacy Policyhttps://realpython.com/privacy-policy/
Terms of Usehttps://realpython.com/terms/
Securityhttps://realpython.com/security/
Contacthttps://realpython.com/contact/
https://realpython.com/

Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover

Robots: max-image-preview:large


URLs of crawlers that visited me.