Understanding integer limit on python3 using Fibonacci series

I need to better understand the max integer number that can be used in python3.
I used the following instructions to get the max integer size.

>> import sys
>> print(sys.maxsize)

So, here I got some integer which I thought was the maximum integer value that python3 will process.
Then, I wrote a small code to get numbers in the Fibonacci series. It looks like this.

for i in range(1000):
    file.write('\n'+ str(fib[-1]))

So, I got my series in the list ‘fib’ and got the series in a text file named ‘fib.txt’. Here, I got the first 1001 numbers in the series (including zero).
Now, when I see the last entry in this series, it shows a very big number.


This number is clearly larger than what ‘sys.maxsize’ showed.
And if I wish I can still do simple mathematical operations on the number so it is not like it is just a string. (I tried only addition and subtraction.)
I do not understand what the max integer is that python can process. Please clarify this.

Thank you.

PS: I am new so please explain accordingly.

>Solution :


In Python, an integer is an int and is unbounded and should not be confused with integer types (int, long etc) in languages like C++.

What python can handle?

Python can handle arbitrarily large integers in computation. Any integer too big to fit in 64 bits (or whatever the underlying hardware limit is) is handled in software. For that reason, Python 3 doesn’t have a sys.maxint constant.

so what does sys.maxsize do?

The value sys.maxsize, on the other hand, reports the platform’s pointer size, and that limits the size of Python’s data structures such as strings and lists.

Leave a Reply