36

If you've noticed, python adds an L on to the end of large exponent results like this:

>>> 25 ** 25
88817841970012523233890533447265625L

After doing some tests, I found that any number below 10 doesn't include the L. For example:

>>> 9 ** 9
387420489

This was strange, so, why does this happen, is there any method to prevent it? All help is appreciated!

Christian Dean
  • 22,138
  • 7
  • 54
  • 87
NotAGoodCoder
  • 417
  • 2
  • 6
  • 9

1 Answers1

48

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.

Note, that L only shows up in the interpreter output, it's just signifying the type. If you print that result instead:

>>> print(25 ** 25)
88817841970012523233890533447265625

The L doesn't get printed.

In Python 3, these types have been merged, so Python 3 outputs:

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
Collin
  • 11,977
  • 2
  • 46
  • 60
  • 2
    I know this is a small issue, but since ```print(25**25)``` is clearly Python 3, the ```L``` wouldn't show regardless. – wnnmaw May 19 '14 at 15:42
  • 7
    The parens work fine in either version, but yes that is true. – Collin May 19 '14 at 15:48
  • 4
    @wnnmaw Why would `print(25**25)` be clearly Python 3? – user189 May 19 '14 at 15:59
  • 2
    @user189, because I didn't know ```print(x)``` was valid Python 2 :P I assumed that meant it would be treated like a function, hence Python 3 – wnnmaw May 19 '14 at 16:05