1. 什么是Python交互式解释器?
Python交互式解释器是一种REPL(Read-Eval-Print Loop)环境。它会读取用户输入的代码,执行代码,并输出结果,随后等待下一个用户输入。这种交互方式使得Python非常适合快速原型开发和实验。
2. 启动Python交互式解释器
2.1 在Windows上启动
- 打开命令提示符:按下
Win+R
,输入cmd
并按回车。 - 输入
python
或python3
并按回车。如果成功,您将看到类似于以下的提示符:
Python 3.x.x (default, Month Day Year, Time)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
2.2 在Mac上启动
- 打开终端:按下
Command + Space
,输入Terminal
并按回车。 - 输入
python3
并按回车。如果成功,您将看到类似于以下的提示符:
Python 3.x.x (default, Month Day Year, Time)
Type "help", "copyright", "credits" or "license" for more information.
>>>
2.3 在Linux上启动
- 打开终端。
- 输入
python3
并按回车。如果成功,您将看到类似于以下的提示符:
Python 3.x.x (default, Month Day Year, Time)
Type "help", "copyright", "credits" or "license" for more information.
>>>
3. 基本使用
3.1 简单的数学运算
在Python交互式解释器中,可以进行简单的数学运算。例如:
>>> 2 + 3
5
&g