Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesSenior Deep-DivesModule 6 · FAANG-2026 deep divesfunctools.cache — hashability is the gatepredict111 / 161
+150 XP
Task
📝 **Task:** Predict the exact output. \`fn(x)\` doubles its input and is wrapped with \`@cache\`. Six prints in order: (1) \`fn(5)\`, (2) repeat \`fn(5)\`, (3) \`fn.cache_info()\`, (4) try \`fn([1, 2, 3])\` — a list, catch the TypeError, (5) \`fn((1, 2))\` — a tuple, (6) \`fn.cache_info()\` again. 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if you get stuck.
Predict the output

Read the code carefully

from functools import cache


@cache
def fn(x):
    return x * 2


print(fn(5))
print(fn(5))
print(fn.cache_info())

try:
    fn([1, 2, 3])
except TypeError as e:
    print(f"err:{e}")

print(fn((1, 2)))
print(fn.cache_info())

What will the program print? Write here:

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…