Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does python add an 'L' on the end of the result of large exponents? [duplicate]

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!

like image 772
NotAGoodCoder Avatar asked May 19 '14 15:05

NotAGoodCoder


People also ask

How do you do exponents in Python?

The ** operator in Python is used to raise the number on the left to the power of the exponent of the right. That is, in the expression 5 ** 3 , 5 is being raised to the 3rd power. In mathematics, we often see this expression rendered as 5³, and what is really going on is 5 is being multiplied by itself 3 times.


Video Answer


1 Answers

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 
like image 198
Collin Avatar answered Sep 28 '22 05:09

Collin