Recursion can be described as a function that calls itself again. So you are calling a function from itsself. What happens is, that you end up in an infinite number of calling, but by default there is a limitation at 1000 times.

If we go on with our example of fans shouting a name with this function they would should “Kroos!” a thousand times until an error occurs.

Or another methapor. Let’s imagine that a function in Python can be compared to a rehearsed move in football. Then the last step in this game move would be to repeat it from the beginning. The team could do this 1000 times until it gets too tired.

Maybe you are asking yourself now, when would I need this if I can use loops instead. Fair question, but in the next example you will see why it can make sense.

You need a function to calculate the faculty of the number n. It is the product of all natural numbers less than or equal to this number n.

As we can see, we recall the function as often until n equals zero to come to the wished result.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s