Code: Select all
from functools import lru_cache
@lru_cache(maxsize=256)
def task_a(a, b):
print(f'Multiplying {a} and {b}')
return a*b
print(task_a(2, 3))
print(task_a(2, 3))
print(task_a(2, 4))
print(task_a(2, 4))
print(task_a(2, 5))
print(task_a(2, 5))
Code: Select all
Multiplying 2 and 3
6
6
Multiplying 2 and 4
8
8
Multiplying 2 and 5
10
10
Wenn nein, woher weiß es dann, dass die Funktion nicht ausgeführt werden soll, wenn dieselben Parameter übergeben werden?