gpt4 book ai didi

Python 为什么 100**0.5 == 4+6 是真的?

转载 作者:太空狗 更新时间:2023-10-30 01:54:42 25 4
gpt4 key购买 nike

>>> 100**0.5 != 4+6
False
>>> 100**0.5 == 4+6
True
>>> 4+6
10
>>> 100**0.5
10.0
>>> 10.0==10
True

谁能告诉我为什么 10.0==10True?我认为 10.0 是 float 而 10 是 int,我知道在 java 中它们不相等。

最佳答案

引自http://docs.python.org/2/library/stdtypes.html#numeric-types-int-float-long-complex

Python fully supports mixed arithmetic: when a binary arithmetic operator has operands of different numeric types, the operand with the “narrower” type is widened to that of the other, where plain integer is narrower than long integer is narrower than floating point is narrower than complex.

因此,10 被扩展为 10.0。这就是为什么 10 == 10.0

关于Python 为什么 100**0.5 == 4+6 是真的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20581565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com