文章目录
1.python的安装
在rhel8中自带python3
在rhel7中安装(rhel7中自带python2)
注意:源码编译安装可以定制化安装
yum install -y gcc
yum install -y zlib-devel.x86_64
./configure --prefix=/usr/local/python3
make && make install
ln -s /usr/local/python3/bin/* /usr/local/bin/
2.python的用法
2.1 python2与python3的语法对比
在python2中:
在python3中:
2.2 python中的注释
注释可以放在代码前对代码进行描述。
对于重点代码行可以在尾行注释。
print('hello world')
# this is a comment
print('hello 2020') #this also a comment
"""
they are all
comment
"""
print('hello python')
2.3 python中的输入输出
在python2中
在python3中
2.3 python的格式化输出(占位符)
%s | str字符串 |
---|---|
%d | int整型 |
%f | float浮点型 |
%% | %百分号 |
可能考虑到是python国内网络的问题,这时我们用国内的镜像源来加速。
pip install ipython -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
注意:在rhel8中可以直接用 pip3 install ipython
ipython
In [1]: name = 'leo'
In [2]: age = 3
In [3]: print('%s age is %d' %(name,age))
leo age is 3
In [4]: print('%s age is %d' %(age,name))
---------------