一、python基础
1、环境python2、python3
[root@python ~]# yum list installed | grep python #检查是否有python包
[root@python ~]# yum list installed | grep epel #检查是否有epel包
[root@python ~]# yum -y install epel-release
[root@python ~]# yum -y install python3
#最新安装3.12可以使用源码安装
[root@python ~]# python3 --version
Python 3.6.8
#进入python的编辑状态
[root@python ~]# python3
#如果直接输入python,会进入到python2中
2、变量和数据类型
(1)三大数据类型
3、数据集合
(1)列表
(2)字典
(3)元组
>>> tup10=(1,2,3,4)
>>> tup10
(1, 2, 3, 4)
>>> tup10[0]
1
>>> tup10[1]
2
>>> tup10[1]=666
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>> list(tup10)
[1, 2, 3, 4]
>>> aa=list(tup10)
>>> aa
[1, 2, 3, 4]
4、选择语句和循环语句
(1)选择语句
(必须要缩进)
①if
单分支
多分支
②swith
(2)循环语句
①for
②while