【发布时间】:2019-04-08 05:41:32
【问题描述】:
刚刚在参加 Google CodeJam 比赛时发现了一些不直观的行为。
input: pow(10, 20) in [pow(10, 20) * 1.0]
output: True
(好吧...)
input: pow(10, 30) in [pow(10, 30) * 1.0]
output: False
(????????????)
(所以呃,这种行为取决于数字的大小?!)
(这是因为大 Python 整数在后台的表示方式不同吗?)
input: True == True
output: False
(好的,一切正常)
input: pow(10, 20) in [pow(10, 20) * 1.0] == pow(10, 20) in [pow(10, 20) * 1.0]
输出:假
(更多??????)
input: pow(10, 20) in [pow(10, 20) * 1.0] and pow(10, 20) in [pow(10, 20) * 1.0]
输出:真
(我完全迷路了)
【问题讨论】:
-
试试
int(1e+30),你也会感到惊讶。
标签: python boolean floating-accuracy largenumber