CBSE Class 12 : Python

Revision tour

CBSE Class 12 : Functions


User defined functions


Recursion Examples

CBSE Class 12: Inbuilt Functions

String Inbuilt Functions
Math Inbuilt Functions
Date and Time Inbuilt Functions
Random Module

CBSE Class 12 : Data File Handling

Data File Handling

Character by Character reading
Word by word reading
Line by line reading

CBSE Class 12 : Data Structures

Introduction to Data Structures
Stacks and its Applications
Implementation of Stacks
Queue and its Applications
Implementation of Queue

CBSE Class 12 : Interface Python With SQL

Class 12 Interface Python With SQL

Example : 1 Student Record management

Example :2 Bank Record Management

CBSE Class 12 : Web Development With Django

Introduction To Django

Example 1: To Test Django

Example 2: To Display Welcome Message

Example 3: To Display Data in Table Format

CBSE Class : Communication And Network Concepts

Full Forms

Computer Networks

Wired and Wireless Networks

New Technologies

Network Devices

Network Stack

IP Address

Transmission Control Protocol

Basic Network Tools and Applications

Switching techniques


Network topologies

Society Law and Ethics

Society Law and Ethics

Digital Property Rights



Cyber Forensics

Technology And Society

Gender and Disability issues


CBSE Class 12 : Sample Papers

Class 12 Python Sample Paper 1
Class 12 Python Sample Paper 1 (Solution)
Class 12 Python Sample Paper 2
Class 12 Python Sample Paper 2 (Solution)

CBSE Class 12 : Practical File

Practical File Programs

CBSE Class 12 :  Python Project

Student management System

Student Management System 2

Banking System

MarkSheet Management System

Stock Management System

Telephone Directory

Digital Directory

CLASS XII: Functions | Recursion

Recursion means iteration. A function is called recursive, if the body of function calls the function itself until the condition for recursion is true. Thus, a Python recursive function has a termination condition.

In other words Recursion means calling a function itself again and again. Recursion is one of the most powerful tools in programming languge.

Why does a recursive function in Python has termination condition?

Well, the simple answer is to prevent the function from infinite recursion.

When a function body calls itself with any condition, this can go on forever resulting an infinite loop or recursion. This termination condition is also called base condition.

Is there any special syntax for recursive functions?

The answer is NO.

In Python, there is no syntactic difference between functions and recursive functions. There is only a logical difference.

Advantages of Python Recursion

  • Reduces unnecessary calling of function, thus reduces length of program.
  • Very flexible in data structure like stacks, queues, linked list and quick sort.
  • Big and complex iterative solutions are easy and simple with Python recursion.
  • Algorithms can be defined recursively making it much easier to visualize and prove.

Disadvantages of Python Recursion

  • Slow.
  • Logical but difficult to trace and debug.
  • Requires extra storage space. For every recursive calls separate memory is allocated for the variables.
  • Recursive functions often throw a Stack Overflow Exception when processing or operations are too large.

Important points related to recursion:

  • There must be a terminating condition in the program which will marks the end of the process. (if not the process will get in an infinte loop)
  • Each time a new recursive call is made a new memory space is allocated to each local variable used by the recursive function.  or we can say that during each recursive call the local variables used in the function gets a different values having the same name.
  • The values in the recursive function are pushed onto the stack with each call to the function and all these values are available to the function call when they are poped from the stack.

Examples Of Recursion

Number Of Visitors