A.6 The Python interpreter
The Python interpreter is a classic example of a command-line-driven Read-Evaluate-Print-Loop (REPL).
Figure A.1 shows how I start Python from the operating system command line.
After displaying version information, Python displays a “>>>
” prompt.
I enter the first command: 2 + 3
.
- Python reads
2 + 3
and parses it into an internal data structure it can manipulate. - It then determines that it must evaluate the expression by applying
“
+
” toint
2
andint
3
. It does so and produces the result5
. - Since the result is not
None
, Python prints5
. - It then displays another “
>>>
” and waits for input.
The next expression is import math
. Python reads and evaluates this code and
loads the math...