天天看點

Recursion

recursion

it is legal for one

function to call another; it is also legal for a function to call itself. it may

not be obvious why what is a good thing, but it turns out to be one of the most

magical things a program can do. for example:

Recursion

if a recursion never

reaches a base case, it goes on making recursive calls forever, and the program

never terminates. this is known as infinite recursion, and it is generally not a

good idea. in most programming environments, a program with infinite recursion

does not really run forever. python reports an error message when the maximum

recursion depth is reached:

Recursion

when the error occurs,

there are 1000 recurse frames on the stack.

form thinking in

python