1print('Hello, world!')2print('Goodbye!')translatorcompilerinterpreterCPythonHello, world!Goodbye!SyntaxError:'(' was never closedLOAD_NAME printLOAD_CONST 'Hello, world!'CALL 1B8 01 00 00 00BF 01 00 00 000F 05CPU0101
Back row: the source code, the translator (compiler or interpreter) and the screenFront row: what the translator makes (bytecode, machine code) and the CPU that runs machine codeTokens: the program, one line of it, machine code, bytecode and the text for the screenBack row: two lines of Python source code, the translator, and the screen. Front row: a bytecode card, a machine-code card and the CPU. A compiler turns the whole program into a machine-code file that the CPU then runs; an interpreter carries the code out as it goes; CPython first compiles to bytecode and then its virtual machine runs it. With the closing bracket missing, nothing runs at all and Python reports SyntaxError: '(' was never closed. Compiled and interpreted are two ends of a range, not two boxes. Java also compiles to bytecode, and some interpreters compile busy parts of a program to machine code while it runs (a JIT); CPython 3.13 added an experimental one.

Code and machine code

  1. Code is text written in a programming language, so people can read and write it. Text like this is called source code. This two-line Python program uses print, which shows text on the screen: first Hello, world!, then Goodbye!

Compiler or interpreter

How Python runs

What happens

;; step 1/9 · source
source code   text people can read and write
language      Python 3
  line 1    print('Hello, world!')
  line 2    print('Goodbye!')
print(...)    shows the text inside on the screen
quotes        mark the text: 'Hello, world!'

Compiled and interpreted are two ends of a range, not two boxes. Java also compiles to bytecode, and some interpreters compile busy parts of a program to machine code while it runs (a JIT); CPython 3.13 added an experimental one. The machine-code card holds real x86-64 bytes: B8 01 00 00 00 is mov eax, 1 (Linux system call 1, write), BF 01 00 00 00 is mov edi, 1 (standard output), and 0F 05 is syscall. A whole Hello, world program needs a few more, to say where the text is and how long it is.