【问题标题】:Why is 2.0==2 True in Python even though 2.0 is float and 2 is int为什么 2.0==2 在 Python 中为真,即使 2.0 是浮点数而 2 是整数
【发布时间】:2022-06-29 23:45:46
【问题描述】:

为什么2.0==2 是真的,即使2.0float2int

print(2.0==2)

输出:

True

【问题讨论】:

标签: python-3.x floating-point integer boolean-operations


【解决方案1】:

嗯,2.0 只是2 的十进制表示,所以2.0 = 2。但是,如果我们正在处理字符串,那么'2.0' != '2'。我希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2014-02-16
    • 2014-09-27
    • 1970-01-01
    • 1970-01-01
    • 2016-11-16
    • 2023-03-10
    • 2017-03-08
    • 1970-01-01
    • 2014-06-17
    相关资源
    最近更新 更多