为什么python会在大指数结果的末尾添加一个“L”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23741762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does python add an 'L' on the end of the result of large exponents?
提问by NotAGoodCoder
If you've noticed, python adds an Lon to the end of large exponent results like this:
如果您已经注意到,python 会在大指数结果的末尾添加一个L,如下所示:
>>> 25 ** 25
88817841970012523233890533447265625L
After doing some tests, I found that any number below 10 doesn't include the L. For example:
在做了一些测试之后,我发现任何低于 10 的数字都不包括L。例如:
>>> 9 ** 9
387420489
This was strange, so, why does this happen, is there any method to prevent it? All help is appreciated!
这很奇怪,那么,为什么会发生这种情况,有什么方法可以防止吗?感谢所有帮助!
采纳答案by Collin
Python supports arbitrary precision integers, meaning you're able to represent larger numbers than a normal 32 or 64 bit integer type. The L
tells you when a literal is of this type and not a regular integer.
Python 支持任意精度整数,这意味着您可以表示比普通 32 位或 64 位整数类型更大的数字。该L
告诉你什么时候文字是这样的类型,而不是一个普通的整数。
Note, that L
only shows up in the interpreter output, it's just signifying the type. If you print that result instead:
请注意,这L
仅显示在解释器输出中,它只是表示类型。如果您改为打印该结果:
>>> print(25 ** 25)
88817841970012523233890533447265625
The L
doesn't get printed.
在L
没有得到打印。
In Python 3, these types have been merged, so Python 3 outputs:
在 Python 3 中,这些类型已经合并,所以 Python 3 输出:
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 24 ** 24
1333735776850284124449081472843776