![5d14c872e60d33599deff3642e316928.png](https://img-blog.csdnimg.cn/img_convert/5d14c872e60d33599deff3642e316928.png)
本节内容我们来学习Python的安装。Python是一门跨平台的语言,可以安装在Windows,Linux/Unix,Mac系统上,今天我们主要介绍Windows系统下的Python3.7.3版本的安装。
下载
首先我们到Python的官网下载Python安装程序:
![764fd1bb39710a1a831c6d0b00655e25.png](https://img-blog.csdnimg.cn/img_convert/764fd1bb39710a1a831c6d0b00655e25.png)
下载python3.7.3
点击红框内容,将python-3.7.3.exe安装程序下载到本地。双击执行:
![ba9176174d1d7754882d759ea0b1229c.png](https://img-blog.csdnimg.cn/img_convert/ba9176174d1d7754882d759ea0b1229c.png)
![b64374c295e3ec8341ddd317f16f844d.png](https://img-blog.csdnimg.cn/img_convert/b64374c295e3ec8341ddd317f16f844d.png)
![aa0e270dc38724f7aa24158c3a662158.png](https://img-blog.csdnimg.cn/img_convert/aa0e270dc38724f7aa24158c3a662158.png)
![2e52ff2a5b30c701421967fca3dd9a12.png](https://img-blog.csdnimg.cn/img_convert/2e52ff2a5b30c701421967fca3dd9a12.png)
注意第一步红框里面需要选中Add Python3.7 to PATH,否则需要自己手动添加到系统环境变量中,然后我们打开终端,输入python,出现以下界面,则Python就安装成功了。
![a097a5d9e19e403dd2a93f4050a539c9.png](https://img-blog.csdnimg.cn/img_convert/a097a5d9e19e403dd2a93f4050a539c9.png)
需要手动设置环境变量的话,需要右键单击“我的电脑”,然后转到属性→高级→环境变量。将Python的路径添加到PATH里就可以了。
使用Python解释器
我们在终端下执行python就可以启动Python的解释器了,实际调用的是C:PythonPython37-32python.exe这个文件。解释器运行的时候可以交互式的读取和执行命令,也可以回看历史命令。
另一种启动解释器的方式是执行代码:
# python -c command [arg]...# 比如C:>python -c "print('hello world')"hello world
python模块也可以作为脚本执行:python -m module [arg]...。比如启动一个http server:
C:>python -m http.serverServing HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
编码
源文件的编码默认是UTF-8,这种编码方式使Python支持世界上大多数的语言的字符作为字符串的值、变量或函数名称以及注释。比如我们可以定义一个中文的变量名:
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)] on win32Type "help