ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy

What is printed?

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

Correct answer: C. 3 0

lru_cache keys on the exact call form, so f(1, 2), f(1, b=2) and f(1) are three different keys. Each one is a miss and none repeats, so there are no hits.

More Python Programming questions

Exams that ask this topic