DrSchool Learn coding, fast.
EN AR BN CS DE EL Search

Recursion — Example 95

Quick explanation + ready code for: Recursion.

Python Recursion Back to examples
Back to language
Syntax: Recursion in Python. ID: #95

Code

def fact(n):
  return 1 if n<=1 else n*fact(n-1)
print(fact(4))

Notes

You can copy this snippet and adapt it. For advanced, add real-world inputs, edge cases, and tests.