0

A function call own function is called

30th Dec 2019, 2:59 AM
Suja Antony
Suja Antony - avatar
2 Antworten
+ 7
Hello! Sorry, but what exactly do you need help with? It's a little difficult to understand your question as of right now, so adding a little more information would make it easier to get you the help you need
30th Dec 2019, 3:09 AM
Faisal
Faisal - avatar
+ 5
I think you might be referring to recursion: when a function calls itself. An example of a recursive function would be this: def factorial(n): if n == 1: # Base Case return 1 else: # General Case return n * factorial(n - 1) This calling this function gets the factorial of n. The base case is the case that ends the recursion. All recursive functions must have one, otherwise you will get a StackOverflowError. The general case is what is done when the base case has not yet been reached. Usually, recursion is used because it will be prettier to look at compared to the iterative way of completing a function or because it makes logical sense to do so. A practical example of when one would use recursion is when iterating through a BinarySearchTree or some other form of a nested data structure. Here is the example in action: https://code.sololearn.com/c9kSCPirhGeH/?ref=app
30th Dec 2019, 3:35 AM
Brian R
Brian R - avatar