Skip to main content
← CoursesSenior Deep-DivesModule 4 · Memory, Profiling, OptimizationPredict: bytecode introspection with `dis`predict61 / 101
💬 Discuss🧪 Playground+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.

Keep going

🔮 Predict the output

Read the code carefully

# Python's compiler folds constant arithmetic at compile time.
# add(a, b) must load both args and call BINARY_OP at runtime.
# add_const() is folded to LOAD_CONST 3; RETURN_VALUE.
print('add_const')

What will the program print? Write here:

📣 Help someone learn PythonShare this lesson with a friend — the first 15 are free, no signup.Tweet

💬 Discussion

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