From the course: Python Quick Start

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Demystifying recursive functions

Demystifying recursive functions - Python Tutorial

From the course: Python Quick Start

Demystifying recursive functions

Recursion means defining something in terms of itself to achieve your objective. Recursion can take place in programming. A function is called recursive if the body of the function calls the function itself. In other words, the process of executing the body of a recursive function may in turn require applying that function again. A recursive function solves a problem by dividing the problem into smaller subproblems and calling the function itself to solve each subproblem. Python supports recursion. For example, say you want to write a function that takes a positive integer as input and returns the factorial of that number. Note that in math, the factorial of a positive integer n denoted by n exclamation point is the product of all positive integers less than or equal to n. So the factorial of 1 is 1. The factorial of 2 is 2 times 1. The factorial of 3 is 3 times 2 times 1. The factorial of 4 is 4 times 3 times 2 times 1 and so on. Now, let's take a look at how to express the factorial…

Contents