JN0-223 practice question 11 of 15

What is the correct sequence for Python script execution?

Full set: 66 questions
Answer options
A: The code is translated to byte code, the byte code is executed in runtime, and then the code is interpreted.
B: The code is interpreted, the code is translated to byte code, and then the byte code is executed in runtime. Correct answer
C: The code is translated to byte code, the code is interpreted, and then the byte code is executed in runtime.
D: The byte code is executed in runtime, the code is interpreted, and then the code is translated to byte code.
Correct Answer:
B. The code is interpreted, the code is translated to byte code, and then the byte code is executed in runtime.
Explanation

The standard Python (CPython) execution model follows a specific sequence. First, the Python interpreter reads and parses the source code (.py file). This initial stage can be broadly termed "interpretation." During this phase, the interpreter translates the human-readable source code into an intermediate, low-level representation called "bytecode." This bytecode is then passed to the Python Virtual Machine (PVM), which executes it at runtime. This hybrid approach combines compilation to an intermediate form with interpretation of that form, providing both portability and performance benefits.

Why Incorrect

A. This sequence is incorrect. Interpretation of the source code is the initial step, not the final one that occurs after runtime execution.
C. This is incorrect. The translation to bytecode is a core part of the overall interpretation process, not a step that happens before it.
D. This is incorrect. Execution is the final stage. The code must be interpreted and translated to bytecode before it can be executed.

References

1. Official Python Documentation

Glossary:

Interpreter: "The program that reads and executes Python code. It has two parts: a compiler that translates the source code into an intermediate code called bytecode

and a virtual machine that executes the bytecode." This confirms that translation to bytecode is part of the interpreter's process before the virtual machine executes it.

Bytecode: "Python source code is compiled into bytecode... This bytecode is then executed by the Python virtual machine." This establishes the sequence of compilation to bytecode

followed by execution.

Source: Python Software Foundation. (2024). Glossary. Python 3.12.3 documentation. Retrieved from https://docs.python.org/3/glossary.html#term-interpreter

2. Official Python Documentation

FAQ:

Section: "Is Python an interpreted or a compiled language?"

Content: "Python is an interpreted language

as opposed to a compiled one

though the distinction can be blurry because of the presence of the bytecode compiler. This means that source files can be run directly without explicitly creating an executable... Python source code is always compiled into bytecode

and this bytecode is then executed by the Python Virtual Machine (PVM)." This source clarifies the compile-to-bytecode step happens first

followed by execution.

Source: Python Software Foundation. (2024). Frequently Asked Questions. Python 3.12.3 documentation. Retrieved from https://docs.python.org/3/faq/general.html#is-python-a-compiled-or-an-interpreted-language

3. MIT OpenCourseWare

6.0001 Introduction to Computer Science and Programming in Python

Fall 2016:

Section: Lecture 2 Notes

"Kinds of languages"

Content: "Python uses a hybrid approach. It compiles source code to a bytecode. This bytecode is then interpreted by a virtual machine." This academic source validates the sequence where source code is first compiled to bytecode

which is then interpreted/executed.

Source: Guttag

J. (2016). Lecture 2: Branching

Conditionals

and Iteration. MIT OpenCourseWare

6.0001 Introduction to Computer Science and Programming in Python. Retrieved from https://ocw.mit.edu/courses/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/resources/lec2/

Scroll to Top