Python基础知识——变量及IDE工具

本文介绍了Python的基础知识,包括在RHEL系统中的安装、Python2与Python3的语法差异、注释、输入输出以及格式化输出。强调了变量的命名规则、类型以及变量类型的特殊用法。此外,还讲解了如何在Python中进行数值类型的转换,并提供了一个计算学生平均成绩和占比的练习。最后,讨论了Python的IDE工具PyCharm的安装。
摘要由CSDN通过智能技术生成

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))
---------------
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值