PCAP Object-Oriented Programming • Set 4
PCAP Object-Oriented Programming Practice Test 4 — 15 questions with explanations. Free, no signup.
Refer to the exhibit. What is printed?
class Cache:
def __init__(self, func):
self.func = func
self.cache = {}
def __call__(self, *args):
if args in self.cache:
return self.cache[args]
result = self.func(*args)
self.cache[args] = result
return result
@Cache
def add(a, b):
return a + b
print(add(1, 2))
print(add(1, 2))