How to control the separation of huge numbers in Python?

I have a 100-digit number, and I'm trying to put all the digits of the number in a list so that I can perform operations on them. For this, I use the following code:

for x in range (0, 1000):
   list[x] = number % 10
   number = number / 10

But the problem I am facing is that I get an overflow error, something like too many float / integer. I even tried using the following alternative

number = int (number / 10)

How can I split this huge number with the result back in an integer type that is not floating?

+4
source share
4 answers

Python 3, number / 10 , float. Python number , OverflowError .

Python sys:

>>> import sys
>>> sys.float_info.max
1.7976931348623157e+308

, //, :

number // 10

int number / 10 ( ). , int , Python 3 ( ).

. , Python 3:

>>> 2**3000 / 10
OverflowError: integer division result too large for a float

>>> 2**3000 // 10
123023192216111717693155881327...
+23

, , :

>>> map(int,list(str(number)))
[1, 5, 0, 3, 0, 0, 7, 6, 4, 2, 2, 6, 8, 3, 9, 7, 5, 0, 3, 6, 6, 4, 0, 5, 1, 2, 4, 3, 7, 8, 2, 5, 2, 4, 4, 5, 4, 8, 4, 0, 6, 6, 4, 5, 0, 9, 2, 4, 8, 9, 2, 9, 7, 8, 7, 3, 9, 9, 9, 7, 0, 1, 7, 4, 8, 2, 4, 4, 2, 9, 6, 9, 5, 1, 7, 1, 3, 4, 8, 5, 1, 3, 3, 1, 7, 9, 0, 1, 0, 1, 9, 3, 8, 4, 2, 0, 1, 9, 2, 9]

int , list . , map int

+6

Python int . , , float , , .

+2

int(number) % 10. .

0

All Articles