Question:
What specific examples of bytecode optimization do you know?
How often asked: Never seen
Suggested by: ALittleMoron
Answer:
The compiler will not evaluate an expression like x = 2 + 3 * 5 during function execution. In the bytecode (the dis module), instead of multiplication and addition instructions, a single, ready-made number load will appear: LOAD_CONST 17.
The concatenation of literal strings like s = "Hello, " + "World" is condensed into a single string "Hello, World" during compilation to .pyc.
Constructs with explicit if False or if 1 == 0 may be partially or completely excluded from the resulting bytecode of branching blocks.
Interview answer explanation:
You will never need this question.