In python a function can call itself.
Use: Looping
To be avoided while using recursion:
- Writing a never ending program.
- Writing a program which uses excessive power.
- Writing a program which uses excess memory.
Example
def recursion(m):
if(m > 0):
result = m + tri_recursion(m – 1)
print(result)
else:
result = 0
return result
print(“\n\nRecursion Example Results”)
recursion(6)
Facebook Comments