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 4 · Memory, Profiling, OptimizationPredict: bytecode introspection with `dis`predict63 / 161
+100 XP
Task
📝 **Question:** Which function has FEWER bytecode ops after constant folding: `def add(a, b): return a + b` or `def add_const(): return 1 + 2`? 📋 Pick the right answer. 💡 **Hint:** Re-read the theory above if unsure.
Predict the output

Read the code carefully

import dis

def add(a, b):
    return a + b

def add_const():
    return 1 + 2

# Imagine running:
#     dis.dis(add)
#     dis.dis(add_const)
#
# Which body compiles to FEWER bytecode ops once CPython's peephole
# / constant-folding passes are done?
#
# Print the name of the winning function: 'add' or 'add_const'.
# Type your prediction.

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…