HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Glossary
  2. /Python and data
  3. /Recursion

What is Recursion?

In short

Recursion is when a function calls itself to solve a smaller version of the same problem. Every recursive function needs a base case that stops the calls.

In simple words

Yes, a function can call itself in Python. Think of the factorial: n!=n×(n−1)!n! = n \times (n-1)!n!=n×(n−1)!, and 0!=10! = 10!=1 is the base case. Each call reduces the problem a little, until it reaches the base case, and the answers are then combined on the way back. Without a base case, Python stops the program with a RecursionError. A recursive check for a palindrome compares the first and last letters and then checks the middle.

Example

This prints 120.

Also searched as: python can a function call itself, palindrome recursion python.

Learn it properly

  • Lessons on this topic
  • Test yourself

Related terms

  • Function (in Python)
  • For Loop

← All glossary terms

Learn it in

  1. A Function That Calls ItselfClass 9 to 10
All lessons on this topic →

Practise

  1. A staircase has n steps. You climb one step or two steps at a time…Medium
  2. Without running anything, say how many subsets there are for lists of 5, 10 and 20 items…Medium
  3. For each function, say whether a memory (a dictionary of answers) would help, and why…Easy
  4. Write a recursive function all_positive(items) that gives True if every item of the list…Medium

Quick questions

  1. A function counts calls to itself, and its only way out is a test for exactly zero. What…Hard
  2. A function multiplies its argument by its own result for a number two smaller, and stops…Hard
  3. def p(n): print(n), then p(n - 1) if n > 1. How many lines does p(5) show?Easy

More Python and data terms

  1. Cell (in a Python notebook)
  2. Class and Special Methods (in Python)
  3. Dictionary (in Python)
  4. If Statement (in Python)
  5. Import (Python modules and libraries)
  6. List (in Python)
All Python and data terms →

Try it yourself

Python labs run in your browser. Type the code, run it and see what happens.

Open a Python lab