Skip to content Skip to sidebar Skip to footer

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?

Solution 1:

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
>>>printsum(range(49999951,50000000))
2449998775

Solution 2:

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

Post a Comment for "How To Avoid The L In Python"