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) 9223372036854775807
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.
fib=[0,1] file=open('fib.txt','a') file.write(str(fib)) for i in range(1000): fib.append(fib[-1]+fib[-2]) file.write('\n'+ str(fib[-1])) file.close()
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.
PS: I am new so please explain accordingly.
In Python, an integer is an
int and is unbounded and should not be confused with integer types (
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
so what does
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.