2.1.2. 交互模式

在终端(tty)输入并执行指令时,我们说解释器是运行在 交互模式(interactive mode)。在这种模式中,它会显示 主提示符(primary prompt),提示输入下一条指令,通常用三个大于号(>>>)表示;连续输入行的时候,它会显示 次要提示符,默认是三个点(...)。进入解释器时,它会先显示欢迎信息、版本信息、版权声明,然后就会出现提示符:

  1. $ python3.9
  2. Python 3.9 (default, June 4 2019, 09:25:04)
  3. [GCC 4.8.2] on linux
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>>

多行指令需要在连续的多行中输入。比如,以 if 为例:

  1. >>> the_world_is_flat = True
  2. >>> if the_world_is_flat:
  3. ... print("Be careful not to fall off!")
  4. ...
  5. Be careful not to fall off!

有关交互模式的更多内容,请参考 交互模式