FZEROX
FZEROX

Reputation: 81

How to avoid the L in Python

>>> sum(range(49999951,50000000))
  2449998775L

Is there any possible way to avoid the L at the end of number?

Upvotes: 4

Views: 2007

Answers (2)

Martijn Pieters
Martijn Pieters

Reputation: 1121594

You are looking at a Python literal representation of the number, which just indicates that it is a python long integer. This is normal. You do not need to worry about that L.

If you need to print such a number, the L will not normally be there.

What happens is that the Python interpreter prints the result of repr() on all return values of expressions, unless they return None, to show you what the expression did. Use print if you want to see the string result instead:

>>> sum(range(49999951,50000000))
2449998775L
>>> print sum(range(49999951,50000000))
2449998775

Upvotes: 7

Inbar Rose
Inbar Rose

Reputation: 43447

The L is just for you. (So you know its a long) And it is nothing to worry about.

>>> a = sum(range(49999951,50000000))
>>> a
2449998775L
>>> print a
2449998775

As you can see, the printed value (actual value) does not have the L it is only the repr (representation) that displays the L

Consult this post

Upvotes: 5

Related Questions