🌐
W3Schools
w3schools.com › python › python_recursion.asp
Python Recursion
Python Examples Python Compiler ... Plan Python Interview Q&A Python Bootcamp Python Training ... Recursion is when a function calls itself....
🌐
W3Schools
w3schools.com › python › gloss_python_function_recursion.asp
Python Function Recursion
Python Examples Python Compiler ... Python Training ... Python also accepts function recursion, which means a defined function can call itself....
Discussions

Not Understanding Python Example of Recursion from W3Schools
I am reading that as result = 6+ tri_recursion(6 - 1) Which is correct, but what is happening then? You enter the next recursion depth as tri_recursion(5) which because 5 > 0 calls 5 + tri_recursion(5 -1) Brings us to the next depth level as tri_recursion(4) -> 4 + tri_recursion(4-1) Next level: 3 + tri_recursion(3 - 1) -> 3 + tri_recursion(2) Next: 2 + tri_recursion(2 - 1) -> tri_recursion(1) Next: 1 + tri_recursion(1 - 1) -> tri_recursion(0) For tri_recursion(0)´ the conditionk > 0is no longer satisfied and thus theelsebranch is executed which executesreturn(0)` With this return we move one level back in the recursion to result = 1 + tri_recursion(1 - 1) -> we have the return value from the tri_recursion(1 - 1) call, which is 0 -> so it becomes result = 1 + 0 -> result = 1 The next executed line in the code is print(result) -> which prints the 1 The else´ branch is skipped and the next executed line isreturn resultwhich brings us one level back up to2 + tri_recursion(2 - 1)- the return value from before is1, so it becomes2 + 1->3` which is what is printed. And this goes on until you are back out of all levels. That is what recursion is. More on reddit.com
🌐 r/learnprogramming
7
1
May 1, 2020
can someone help me how to use recursion in python
Recursion is the same across many different languages Probably worth looking into a recrusion tutorial, such as this: https://youtu.be/IJDJ0kBx2LM (even just watching the first 30 mins or so would be useful to you) More on reddit.com
🌐 r/learnpython
15
7
December 10, 2023
🌐
w3resource
w3resource.com › python-exercises › data-structures-and-algorithms › python-recursion.php
Python Data Structures and Algorithms: Recursion - Exercises, Practice, Solution - w3resource
July 28, 2025 - Write a Python program to sum recursion lists using recursion. Test Data: [1, 2, [3,4], [5,6]] Expected Result: 21 Click me to see the sample solution ... Write a Python program to get the factorial of a non-negative integer using recursion.
🌐
W3Schools
localdev.w3schools.com › python › gloss_python_function_recursion.asp
Python Function Recursion
Python also accepts function recursion, which means a defined function can call itself. Recursion is a common mathematical and programming concept. It means that a function calls itself.
🌐
W3Schools
w3schools.com › python › trypython.asp
W3Schools online PYTHON editor
Run ❯ Get your own Python server · ❯Run Code Ctrl+Alt+R Change Orientation Ctrl+Alt+O Change Theme Ctrl+Alt+D Go to Spaces Ctrl+Alt+P · Recursion Example Results: 1 3 6 10 15 21
🌐
W3schools
w3schools.tech › tutorial › python › python_recursion
Python - Recursion: A Beginner's Guide - Python Miscellenous - W3schools
In simple terms, recursion is when a function calls itself to solve a problem. ... We define a function called countdown that takes a number n. ... Otherwise, we print n and then call countdown again with n - 1. This is recursion in action!
🌐
Real Python
realpython.com › python-recursion
Recursion in Python: An Introduction – Real Python
October 21, 2023 - 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.
🌐
Reddit
reddit.com › r/learnprogramming › not understanding python example of recursion from w3schools
r/learnprogramming on Reddit: Not Understanding Python Example of Recursion from W3Schools
May 1, 2020 -

I'm pretty sure I understand what recursion is (a function calling itself???) but I am having a lot of trouble understanding how this code works: https://www.w3schools.com/python/trypython.asp?filename=demo_recursion

def tri_recursion(k):
if(k > 0):
result = k + tri_recursion(k - 1)
print(result)
else:
result = 0
return result
print("\n\nRecursion Example Results")
tri_recursion(6)

From how I see it, k = 6. So when I see

result = k + tri_recursion(k-1)

I am reading that as result = 6+ tri_recursion(6 - 1)

What am I not understanding here?

🌐
Programiz
programiz.com › python-programming › recursion
Python Recursion (Recursive Function)
Factorial of a number is the product of all the integers from 1 to that number. For example, the factorial of 6 (denoted as 6!) is 1*2*3*4*5*6 = 720. def factorial(x): """This is a recursive function to find the factorial of an integer""" if x == 1: return 1 else: return (x * factorial(x-1)) num = 3 print("The factorial of", num, "is", factorial(num))
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › recursion-in-python
Recursion in Python - GeeksforGeeks
A recursive function calls itself in its body.
Published   May 19, 2026
🌐
Pythonspot
pythonspot.com › recursion
Python Recursion — Tutorial with Examples | Pythonspot
January 1, 2026 - Learn Python recursion with examples. Recursive functions and base cases.
🌐
DataCamp
datacamp.com › tutorial › recursion-in-python
Recursion in Python: Concepts, Examples, and Tips | DataCamp
April 9, 2025 - Learn recursion in Python with examples, key concepts, and practical tips. Understand base cases, recursive functions, and when to use recursion over iteration.
🌐
W3Schools
w3schools.com › programming › prog_recursion.php
What is Recursion?
Always make sure you have a base case, or the recursion may go on forever! ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python ...
🌐
W3Schools
w3schools.com › c › c_functions_recursion.php
C Function Recursions
C Examples C Real-Life Examples C Exercises C Quiz C Code Challenges C Practice Problems C Compiler C Syllabus C Study Plan C Interview Q&A ... Recursion is the technique of making a function call itself.
🌐
Stack Overflow
stackoverflow.com › questions › 61771314 › question-about-a-recursion-example-i-understand-the-code-and-the-program-runs
python 3.x - Question about a recursion example, i understand the code, and the program runs ok, but it doesn't run like i expect it to - Stack Overflow
This means the if-condition is false, so the following indented code block (two lines here) is skipped, and the else statement is executed instead. So the value 0 is assigned to result. Nothing is printed, because there is no print statement here. Then the function returns result, which is 0 here. tri_recursion(1) calls the function with k=1.
🌐
YouTube
youtube.com › watch
Recursion for Python Beginners with Recursive Function ...
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
🌐
Codecademy
codecademy.com › learn › learn-recursion-python › modules › recursion-python › cheatsheet
Learn Recursion with Python: Recursion: Python Cheatsheet | Codecademy
Given an input of index N, the recursive function has two base cases – when the index is zero or 1. The recursive function returns the sum of the index minus 1 and the index minus 2. The Big-O runtime of the Fibonacci function is O(2^N). ... One can model recursion as a call stack with execution contexts using a while loop and a Python list.
🌐
Python Course
python-course.eu › advanced-python › recursive-functions.php
1. Recursive Functions | Advanced | python-course.eu
And this is what a recursive definition or a recursive function does: It is "running back" or returning to itself. Most people who have done some mathematics, computer science or read a book about programming will have encountered the factorial, which is defined in mathematical terms as
🌐
Educative
educative.io › blog › recursion-in-python-tutorial
Recursion in Python Tutorial
October 31, 2025 - Base case and recursive case: Every recursive function needs a base case that stops execution and a recursive case that moves closer to that stopping point on each call. Python's recursion limit: The default call stack supports roughly 1,000 frames, and exceeding it raises a RecursionError, so deep recursions often need an iterative redesign.