Building on Class 9 function basics, this topic covers recursion (functions that call themselves), lambda expressions (anonymous functions), higher-order functions (map, filter), and modules for code organisation.
Recursion: a function that calls itself. Must have a base case (stopping condition) to avoid infinite recursion. Factorial: def factorial(n): if n == 0: return 1; return n * factorial(n-1). How it works: factorial(4) → 4 * factorial(3) → 4 * 3 * factorial(2) → ... → 4 * 3 * 2 * 1 = 24. Classic examples: Fibonacci, power, sum of digits, Tower of Hanoi. Python's default recursion limit: 1000 calls.
Lambda: anonymous function for simple operations. square = lambda x: x**2; square(5) → 25. map(): apply function to every item. list(map(lambda x: x**2, [1,2,3,4])) → [1,4,9,16]. filter(): keep items where function returns True. list(filter(lambda x: x%2==0, [1,2,3,4])) → [2,4]. Modules: import math (math.sqrt, math.pi), import random (random.randint, random.choice), import os, import datetime. Create your own: save functions in mymodule.py, use import mymodule.
Use recursion when the problem has a natural recursive structure — tree traversal, mathematical sequences (factorial, Fibonacci), divide-and-conquer algorithms, exploring all possibilities (backtracking). Use loops when you need simple iteration — processing a list, counting, searching. Recursion is elegant but uses more memory (each call adds to the call stack) and can be slower than loops. In Python, prefer loops for performance-critical code. Use recursion when it makes the logic significantly clearer.
Book a Trial + Diagnostic session. Get a personalized Learning Path with clear milestones, tutor match, and a plan recommendation — all within 24 hours.
Book Trial + Diagnostic →