如何在 Python 中输入 Googol?

now*_*wox 3 python integer long-integer

我听说 Python 对整数没有任何上限。所以我想试一试:

a = 1e100
b = 1
c = a + b + a
c - 2 * a
> 0.0
Run Code Online (Sandbox Code Playgroud)

不幸的是,我意识到写作1e2返回一个浮点数而100返回一个整数。

然后我测试了long('1' + '0' * 100)哪个有效。

a = long('1' + '0' * 100)
b = 1
c = a + b + a
c - 2 * a
> 1L
Run Code Online (Sandbox Code Playgroud)

这个解决方案是影响Googol到变量的唯一方法吗?

后续问题:

如何在计算过程中避免浮点和定点之间的混淆?

aar*_*ler 5

你可以像这样得到一个 Googol:

10**100
Run Code Online (Sandbox Code Playgroud)