QuizzesBytecode & How CPython Runs Your Code — Concept Check
intermediate
python

Bytecode & How CPython Runs Your Code — Concept Check

Questions on Bytecode & How CPython Runs Your Code. CPython compiles source to bytecode (inspect it with dis), caches it in __pycache__, and executes it in the interpreter loop — since 3.11, an adaptive specializing interpreter rewrites hot bytecode for big speedups.

7 minutes 7 questions Pass at 70%
Time Limit
7 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

7 questions on Bytecode & How CPython Runs Your Code — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A Python developer notices that their script runs faster after the first execution. What could be the reason?

    • AThe script is compiled to machine code after the first run.
    • BThe script uses a faster algorithm after the first run.
    • CThe bytecode is cached in __pycache__ after the first run.
    • DThe interpreter optimizes the script after the first run.
  2. 2.In Python 3.11+, why might a loop with consistent data types run faster after several iterations?

    • AThe loop uses a faster algorithm after warm-up.
    • BThe loop is automatically parallelized.
    • CThe interpreter specializes bytecode for observed types.
    • DThe loop is converted to machine code.
  3. 3.A developer uses dis to inspect a function and sees LOAD_FAST instructions. What does this indicate?

    • AThe function is compiled to machine code.
    • BThe function is optimized for parallel execution.
    • CThe function uses local variables efficiently.
    • DThe function uses global variables efficiently.
  4. 4.Why is x += 1 not considered an atomic operation in Python?

    • APython automatically optimizes it to atomic.
    • BIt is a single bytecode instruction.
    • CPython locks the variable during the operation.
    • DIt involves multiple bytecode instructions.
  5. 5.A developer upgrades Python from 3.10 to 3.12 and notices a speedup. What is a likely reason?

    • AThe code is now compiled to machine code.
    • BThe interpreter runs in parallel threads.
    • CThe bytecode is now cached in __pycache__.
    • DThe adaptive interpreter specializes hot code paths.
  6. 6.What happens when you modify a .py file that has been cached in __pycache__?

    • AThe interpreter runs the old bytecode until manually updated.
    • BThe interpreter recompiles the source to bytecode.
    • CThe cached bytecode is automatically updated.
    • DThe cached bytecode is ignored until manually cleared.
  7. 7.Why might local variables be accessed faster than global variables in Python?

    • ALocal variables are compiled to machine code.
    • BLocal variables use LOAD_FAST, a fast array index.
    • CLocal variables are cached in __pycache__.
    • DLocal variables are optimized by the JIT compiler.