一:变量与对象存储
1.x=20
y="tom"
x="jerry"
变量名和数值单独存储,没被引用的会被程序自动回收
二:整形、浮点型
1、Python不用变量声明,变量的大小有机器硬件、cpu来决定大小
2、运算符 + 、-、* 、/、//、%、
3、强制转换,如:
(1)int(3.1415926)=3 10+int("30")=40
(2)math模块
1) x=4.1413567890 math(x)=4 math.floor(3.99)=3 math.floor(-3.14)=-4 往下取整
math.trunc(3.14)=3 math.trunc(3.99)=3 math.trunc(-3.14)=-3 trunc截短
math.ceil(3.14)=4 math.ceil(3.99)=4 math.ceil(-3.14)=-2 向上取整
2)如果只想四舍五入用round round(3.14)=3 round(4.56)=5
3) 取次方 math.pow(2,4)=16
(3)decimal类,使浮点型更精准
如:0.1+0.1+0.1-0.3=5.551115123125783e-17
导入:import decimal
a = decimal.Decimal('0.1') + decimal.Decimal('0.1') + decimal.Decimal('0.1') - decimal.Decimal('0.3') print(a)打印出来的就是0
三:bool本质