Bird
0
0

What will be the output of this code snippet?

medium📝 component behavior Q13 of 15
Django - Caching
What will be the output of this code snippet?
from django.core.cache import cache
cache.set('count', 5)
value = cache.get('count')
print(value)
A0
BNone
CKeyError
D5
Step-by-Step Solution
Solution:
  1. Step 1: Analyze cache.set usage

    The code sets the key 'count' with value 5 in the cache.
  2. Step 2: Analyze cache.get usage

    Retrieving 'count' returns the stored value 5, so print outputs 5.
  3. Final Answer:

    5 -> Option D
  4. Quick Check:

    cache.get returns stored value 5 [OK]
Quick Trick: cache.get returns stored value or None if missing [OK]
Common Mistakes:
MISTAKES
  • Expecting None if key was just set
  • Thinking cache.get raises KeyError
  • Confusing default return values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes