为什么2.0 == 2在python中是true,即使2.0是float,而2是int
为什么2.0 == 2
即使2.0
是float
和2
is int
int ?
print(2.0==2)
输出:
True
Why is 2.0==2
True even though 2.0
is float
and 2
is int
?
print(2.0==2)
output:
True
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,
2.0
只是2
的小数表示,因此2.0 = 2
。但是,如果我们正在处理字符串,则'2.0'!='2'
。我希望有帮助。Well,
2.0
is just a decimal representation of2
, so2.0 = 2
. If, however, we are dealing with strings, then'2.0' != '2'
. I hope that helps.