Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Higher-order functions and operations on callable objects in python

@cache
def factorial(n):
    return n * factorial(n-1) if n else 1

>>> factorial(10)      # no previously cached result, makes 11 recursive calls
3628800
>>> factorial(5)       # just looks up cached value result
120
>>> factorial(12)      # makes two new recursive calls, the other 10 are cached
479001600
Source by docs.python.org #
 
PREVIOUS NEXT
Tagged: #functions #operations #callable #objects #python
ADD COMMENT
Topic
Name
1+7 =