1.浮点数的介绍函数
2.浮点型的运算code
a = 1.25 b = 0.3535 print(a-b) #输出:0.8965000000000001
a = 1 b = 0.25 print(a + b,type(a+b)) #输出:1.25 <class 'float'> print(a - b,type(a-b)) #输出:0.75 <class 'float'> print(a * b,type(a*b)) #输出:0.25 <class 'float'> print(a / b,type(a/b)) #输出:4.0 <class 'float'>
#整数转为浮点数 a = 1 print('a的类型为:',type(a)) #输出:a的类型为: <class 'int'> print(float(a)) #输出:1.0 print('转换后a的类型为:',type(float(a))) #输出:转换后a的类型为: <class 'float'> #字符串转为浮点数 b = '123' print('b的类型为:',type(b)) #输出:a的类型为: b的类型为: <class 'str'> print(float(b)) #输出:123.0 print('转换后b的类型为:',type(float(b))) #输出:转换后b的类型为: <class 'float'>