0
点赞
收藏
分享

微信扫一扫

终于向她(他)表白了!爱上Python之安装及基础操作


基础环境:

Linux系统安装Python3(默认安装Python2,不要卸载,命令程序依赖它)
配yum仓库
cd /etc/yum.repos.d/
vim python3.repo
删除源yum文件,创建python3文件添加内容并保存

[base]
name=CentOS-\$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/os/\$basearch/
enabled=1
gpgcheck=0

#released updates
[updates]
name=CentOS-\$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/updates/\$basearch/
#baseurl=https://mirrors.aliyun.com/centos/\$releasever/updates/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=updates
enabled=1
gpgcheck=0

#additional packages that may be useful

[centosplus]
name=CentOS-\$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/centosplus/\$basearch/
#baseurl=https://mirrors.aliyun.com/centos/\$releasever/centosplus/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=centosplus
enabled=1
gpgcheck=0

[cloud]
name=CentOS-\$releasever - Cloud
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/cloud/\$basearch/openstack-train/
#baseurl=https://mirrors.aliyun.com/centos/\$releasever/cloud/\$basearch/openstack-train/
enabled=1
gpgcheck=0

[paas]
name=CentOS-\$releasever - paas
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/paas/\$basearch/openshift-origin13/
#baseurl=https://mirrors.aliyun.com/centos/\$releasever/paas/\$basearch/openshift-origin13/
enabled=1
gpgcheck=0

[kvm]
name=CentOS-\$releasever - kvm
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/virt/\$basearch/kvm-common/
#baseurl=https://mirrors.aliyun.com/centos/\$releasever/virt/\$basearch/kvm-common/
enabled=1
gpgcheck=0

[extras]
name=CentOS-\$releasever - extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/\$releasever/extras/\$basearch/
#baseurl=https://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/
enabled=1
gpgcheck=0

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=0

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=0

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=0

终于向她(他)表白了!爱上Python之安装及基础操作_linux


验证:

终于向她(他)表白了!爱上Python之安装及基础操作_开发语言_02

创建Python3的虚拟环境(工作场景可能需要多个环境来操作)

mkdir /opt/py3  创建工作目录
cd /opt/py3
python3 -m venv /opt/py3 命令创建环境
cd bin/ 进入可执行文件目录
source ./activate 进入虚拟环境
deactivate 退出虚拟环境

终于向她(他)表白了!爱上Python之安装及基础操作_开发语言_03

验证:

终于向她(他)表白了!爱上Python之安装及基础操作_centos_04


安装扩展功能插件:

终于向她(他)表白了!爱上Python之安装及基础操作_linux_05


升级pip

终于向她(他)表白了!爱上Python之安装及基础操作_开发语言_06

基本操作:

1、 注释
单行 #
多行 " " "或’’’

(py3) [root@ansible bin]# cd lesson9/
(py3) [root@ansible lesson9]# ls
(py3) [root@ansible lesson9]# vim notify.py
(py3) [root@ansible lesson9]# chmod +x notify.py
(py3) [root@ansible lesson9]# ./notify.py

编辑内容:vim notify.py

终于向她(他)表白了!爱上Python之安装及基础操作_开发语言_07


设置执行权:

终于向她(他)表白了!爱上Python之安装及基础操作_linux_08


终于向她(他)表白了!爱上Python之安装及基础操作_开发语言_09


终于向她(他)表白了!爱上Python之安装及基础操作_centos_10


执行脚本:不显示#或​​'''​​注释的内容。

终于向她(他)表白了!爱上Python之安装及基础操作_开发语言_11


2、 操作符

  • 标准算术操作符 + - * / //(整除) % (取模,得余数) ** 次方
  • 终于向她(他)表白了!爱上Python之安装及基础操作_linux_12

  • 标准比较操作符 < <= > >= == !=
  • 终于向她(他)表白了!爱上Python之安装及基础操作_linux_13


  • 终于向她(他)表白了!爱上Python之安装及基础操作_python_14


  • 终于向她(他)表白了!爱上Python之安装及基础操作_linux_15

  • 逻辑操作符 and or not(优先级not>and>or)
  • 终于向她(他)表白了!爱上Python之安装及基础操作_开发语言_16


  • 终于向她(他)表白了!爱上Python之安装及基础操作_linux_17


  • 终于向她(他)表白了!爱上Python之安装及基础操作_linux_18

  • 3、 表达式 1+3等等
    4、变量与赋值(a的值变化,b的id不会随a的变化改变)
    变量定义方法:字母、数字(不能以数字开头)、下划线,不能和关键字一样
    动态语言:不用预先声明变量类型
  • 终于向她(他)表白了!爱上Python之安装及基础操作_python_19

数据类型

字符串(/或r转义)

查看帮助

终于向她(他)表白了!爱上Python之安装及基础操作_linux_20

终于向她(他)表白了!爱上Python之安装及基础操作_开发语言_21

1、 首字母大写

终于向她(他)表白了!爱上Python之安装及基础操作_python_22


终于向她(他)表白了!爱上Python之安装及基础操作_python_23


驼峰式

终于向她(他)表白了!爱上Python之安装及基础操作_开发语言_24

2、 所有变大写或小写

终于向她(他)表白了!爱上Python之安装及基础操作_centos_25

3、 取反(大写变小写,小写变大写;源值不变,只是本次输出结果)

终于向她(他)表白了!爱上Python之安装及基础操作_linux_26


4、格式

居中

终于向她(他)表白了!爱上Python之安装及基础操作_自动化运维_27


左对齐

终于向她(他)表白了!爱上Python之安装及基础操作_开发语言_28

右对齐(right justify)

终于向她(他)表白了!爱上Python之安装及基础操作_python_29


空一格tab(\转义)

终于向她(他)表白了!爱上Python之安装及基础操作_linux_30


格式化输出

以数字序号的方式:

终于向她(他)表白了!爱上Python之安装及基础操作_python_31


以变量的方式:

终于向她(他)表白了!爱上Python之安装及基础操作_linux_32


填充总数为10的*号;后面的值是从0开始,0,1

终于向她(他)表白了!爱上Python之安装及基础操作_centos_33


举报

相关推荐

0 条评论