The reason there's an L
there is because this is too large to fit into an int
,* so it's a long
. See Numeric Types — int
, long
, float
, complex
in the docs for more details.
So, why do you get that L
, and how do you get rid of it?
Python has two different ways to turn a value into a string representation:
repr
either returns the canonical source-code representation, or something like <__main__.Eggs at 0x10fbd8908>
).
str
returns a human-friendly representation.
For example, for strings, str('abc')
is abc
, while repr('abc')
is 'abc'
.
And for longs, str(1L)
is 1
, while repr(1L)
is 1L
.
When you just type an expression at the interactive prompt, it uses repr
. But when you use the print
command, it uses str
. So, if you want to see the value without the L
, just print
it:
print randint(100000000000000000000, 999999999999999999999)
If you want to, e.g., save the string in a variable or write it to a file, you have to call str
explicitly.
But if you just want to use it as a number, you don't have to worry about this at all; it's a number, and int
and long
values can be intermixed freely (as of Python 2.3 or so).
And if you're trying to store it in a MySQL database, whichever MySQL interface you use won't care whether you're giving it int
values or long
, as long as they fit into the column type.**
Or you could upgrade to Python 3.x, where there is no separate long
type anymore (all integers are int
, no matter how big) and no L
suffix.
* The exact cutoff isn't documented anywhere, but at least for CPython, it's whatever fits into a C long
on your platform. So, on most 64-bit platforms, the max value is (1<<63)-1; on the other 64-bit platforms, and all 32-bit platforms, it's (1<<31)-1. You can see for yourself on your platform by printing sys.maxint
. At any rate, your number takes 70 bits, so unless someone ports Python 2.x to a platform with 128-bit C long
s, it won't fit.
** Note that your values are too big to fit into even a MySQL BIGINT
, so you're going to be using either DECIMAL
or NUMERIC
. Depending on which interface you're using, and how you've set things up, you may have to convert to and from strings manually. But you can do that with the str
and int
functions, without worrying about which values fit into the int
type and which don't.)