Python
Recursive Functions
detailed
A function that calls the current function itself within a function is a recursive function
The following is an example of a recursive function:
The first time a person touches a recursive function, it gets disoriented by the call itself, and looking at the function call above, the result will be:
Why did you come up with the above results? Because all of the code behind the calling function itself is forgotten, which is the Python code after the else.
The actual output of this recursive function is the following result:
I believe you see here are a little bit, small, the same, I see this recursive function for the first time, can only understand the first result. That's because, when most people are doing things, break the first thing, be arranged to do the second thing, will forget the first thing follow-up things, if in doing the second thing, and interrupted, be arranged to do the third thing, will be the first, the second to do the follow-up things to forget ..., This is why the recursive function is not understood.
Here I have done a decomposition of this recursive function, I hope to help everyone.
To explain the recursive function, when calling the recursive function Digui (3), the following procedure is performed:
when the function itself is called, the code after it does not end, but waits for the condition to be False, and then after executing the code, the same color of the print () statement waits for the corresponding color function.
Python recursive functions in a detailed