Code Explanatiion:
Import the Required Function
from functools import lru_cache
lru_cache is imported from Python’s built-in functools module.
It is used to cache (store) results of function calls so that if the same input is used again, Python can return the result from memory instead of re-computing.
LRU means Least Recently Used — it removes old cached results when cache is full.
Apply the lru_cache Decorator
@lru_cache(None)
This decorator is applied to the function below it.
None means no limit on cache size (infinite caching allowed).
After this, Python will remember the output of function calls based on arguments.
Define the Function
def f(x): return x*2
A function named f is defined.
It takes an input x and returns x * 2.
So if x = 5, the function returns 10.
Call and Print the Function Result
print(f(5))
The function f(5) is executed.
Since 5 * 2 = 10, the output is:
Final Output
10
.png)

0 Comments:
Post a Comment