本篇内容主要讲解“Python中的浮点型是什么”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Python中的浮点型是什么”吧!
1.浮点数的介绍
2.浮点型的运算
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'>到此,相信大家对“Python中的浮点型是什么”有了更深的了解,不妨来实际操作一番吧!这里是天达云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!