整数5和浮点数5.0之间有区别吗? [英] Is there a difference between an int of 5 and a float of 5.0?

查看:352
本文介绍了整数5和浮点数5.0之间有区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了浮点数有小数点外,我对int为5和float为5.0之间是否存在任何差异感到困惑.

I am confused on whether there is or is not any difference between and int of 5 and a float of 5.0, besides the float having a decimal.

使用int不能使用float进行哪些操作?拥有两个单独的类型,而不是仅仅让所有内容都首先成为float,这有什么意义?

What are some of the things I can do with an int that I can't with a float? What is the point of having two separate types, instead of just letting everything be a float in the first place?

推荐答案

它们是不同的数据类型:

They are different data types:

 type(5)     # int
 type(5.0)   # float

因此,严格来讲,它们并不相同.

And therefore they are not, strictly speaking, the same.

但是,它们是相等的:

5 == 5.0     # true

这篇关于整数5和浮点数5.0之间有区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆