Linux系统下编写Python程序的两种方法及CentOS7升级Python版本指南
目录

编写 Python 程序方法 1
1) 进入 liunx 系统中的命令行
2) 输入 python3,输入 python3 表示 python 的第三个版本,如果只输入 python,则表示你正在使用 python 的第二个版本
在 CentOS7 上升级 Python 版本 ~~~> 点击这里
<code>[root@hya ~]# python Python 3.9.0 (default, Nov 2 2020, 11:26:43) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
3) 输入代码 (code demo)。
>>> print('welcome to hya')
welcome to hya
编写 Python 程序方法 2
1) 编写带有后缀 .py 的脚本
[root@hya ~]# vim python.py
#!/usr/bin/python
#coding=utf-8
print("welcome to hya")
2) 执行权限是必需的,就像 shell 脚本一样
[root@hya ~]# chmod +x python.py
[root@hya ~]# ls -l python.py #查看有执行的权限了
-rwxr-xr-x. 1 root root 56 11月 2 14:57 python.py
3) 进行演示
[root@hya ~]# python3 python.py
welcome to hya
总结
对于编写 python 程序,我总结了两种方法,在实际开发中我们使用第二种方法,它保存在 xxx.py 文件中,以便下次可以直接执行和运行。在第一种情况下,您每次运行程序时都需要重新进入该程序,这是吃力不讨好的。如果您喜欢它,您可以连续单击三次。