Python implements the Fibonacci recursive function.
This article uses a simple example to describe how python implements the Fibonacci series recursive function. The code is concise and easy to understand. Share it with you for your reference.
The main function code is as follows:
Def fab (n): if n = 1: return 1 if n = 0: return 0 else: result = int (fab (n-1 )) + int (fab (n-2) return result
The test code is as follows:
For I in range (10): print fab (I)
I hope this article will help you learn Python programming.
Python problems. For recursive functions that run recursively, there is return in the function. The function I wrote is as follows:
Why not return? The last return value is the number of different characters.
Recursive problems in python
Pthon has two procedures in recursion. First, you input X, for example, X = 5, X = 5 without an initial value. You can only obtain x = 4 because age (5) = age (4) + 2, x = 4 is not initialized, and so on until x = 1, x = 1 has an initial value age (1) = 10, so age (2) can be calculated, age (2) has a value, continue to calculate age (3) until age (5), there are two processes to go to the bottom layer and then return to the top layer