+ 1
What is Recursion in python with examples ?
2 Answers
+ 6
recursion is if a function calls itself.
Most famous example is probably calculating factorials:
factorial(4) = 4*3*2*1
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
+ 3
Great video good explaining recursion with a recursive implementation of Hanoi towers game:
https://youtu.be/rVPuzFYlfYE