views:

126

answers:

3

When calculating

math.factorial(100)

I get:

93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000L

Why is there an L at the end of the number?

+2  A: 

The L means that it's a long integer

Nathan Fellman
Which is a BigInt in Python, right?
Hamish Grubijan
nopey. They are longs, not C longs but longs. http://www.python.org/dev/peps/pep-0237/
msw
+8  A: 

L means it's a long as opposed to an int. The reason you see it is that you are looking at the repr of the long

You can use

print math.factorial(100)

or

str(math.factorial(100))

if you just want the number

gnibbler
A: 

I believe that you are working with a BigInt, which is known as long in Python - it expands and occupies a variable amount of RAM as needed. The name long can be confusing, as that means a specific number of bytes in a handful of popular languages of today. The following can help you get at the number of bytes it takes to store the object.

Python 2.6.2 (r262:71600, Aug 14 2009, 22:02:40) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import sys
>>> a = 1
>>> sys.getsizeof(a)
12
>>> import math
>>> sys.getsizeof(math.factorial(100))
84
>>> sys.getsizeof(math.factorial(200))
182
>>> 
Hamish Grubijan
Although informative, this isn't related to the question and I've seen people get downvoted (pettily, if I may opine) for less. You might want to delete this.
msw
@msw, let's see what happens. It is not as if I care that much about my rep - it is just a number. If it goes down, I will throw in a popular answer fast enough and will more than make up for it.
Hamish Grubijan