ProgrammingVery hardTCS NQT · Wipro pattern

What is printed?

What is printed?
from functools import lru_cache
class C:
    @lru_cache(maxsize=None)
    def f(self, x):
        return x * 2
a, b = C(), C()
a.f(1)
b.f(1)
print(C.f.cache_info().misses, a.f(1) == b.f(1))
  1. A. 1 True
  2. B. 2 False
  3. C. 2 True
  4. D. 0 True

Correct answer: C. 2 True

The cache key includes self, and each instance is a different key, so each call misses once. Later calls with the same instance and argument hit the cache.

More Python Programming questions

Exams that ask this topic