Python Recursion

Share

In python a function can call itself.

Use: Looping

To be avoided while using recursion:

  1. Writing a never ending program.
  2. Writing a program which uses excessive power.
  3. 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

Leave a Reply

Your email address will not be published. Required fields are marked *