Python 的交互模式是如何工作的?

How does Python's interactive mode work?

我想知道 Python 交互模式是如何工作的。通常当你在 CPython 上 运行 Python 脚本时,它会经过词法分析、解析、编译成 .pyc 文件,最后 .pyc 文件被解释。

使用交互模式时是否也会发生这 4 步过程,是否有更有效的实施方式?

Python 有两种基本模式:普通模式和交互模式。正常模式是脚本和完成的 .py 文件在 Python 解释器中是 运行 的模式。交互模式是一个命令行 shell,它为每个语句提供即时反馈,而 运行ning 之前在活动内存中输入的语句。当新行被输入解释器时,输入的程序将被部分和整体评估。
.cpy 文件也是如此。交互模式基本上为每一行完成整个过程。我非常怀疑是否有更有效的方法来做到这一点。
iPython 笔记本的工作方式类似。

来自文章Is Python interpreted or compiled? Yes.

Another important Python feature is its interactive prompt. You can type Python statements and have them immediately executed. This interactivity is usually missing in "compiled" languages, but even at the Python interactive prompt, your Python is compiled to bytecode, and then the bytecode is executed. This immediate execution, and Python' lack of an explicit compile step, are why people call the Python executable, "the Python interpreter."