我知道Python可以处理任意大的整数,那么为什么在使用科学计数法时它不会给我一个任意大的整数呢?为什么1e23和10**23有所不同?
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> for x in range(30):
... x1 = eval('long(1e{})'.format(x))
... x2 = eval('long(1{})'.format('0' * x))
... print x1, 'OK' if x1 == x2 else 'YUCK!'
...
1 OK
10 OK
100 OK
1000 OK
10000 OK
100000 OK
1000000 OK
10000000 OK
100000000 OK
1000000000 OK
10000000000 OK
100000000000 OK
1000000000000 OK
10000000000000 OK
100000000000000 OK
1000000000000000 OK
10000000000000000 OK
100000000000000000 OK
1000000000000000000 OK
10000000000000000000 OK
100000000000000000000 OK
1000000000000000000000 OK
10000000000000000000000 OK
99999999999999991611392 YUCK!
999999999999999983222784 YUCK!
10000000000000000905969664 YUCK!
100000000000000004764729344 YUCK!
1000000000000000013287555072 YUCK!
9999999999999999583119736832 YUCK!
99999999999999991433150857216 YUCK!
<num>e<num>
总是被解析为浮点数。 - mgilson