maxsize attribute of the sys module fetches the largest value a variable of data type Py_ssize_t can store. It is the Python platform’s pointer that dictates the maximum size of lists and strings in Python. The size value returned by maxsize depends on the platform architecture:
- 32-bit: the value will be 2^31 – 1, i.e. 2147483647
- 64-bit: the value will be 2^63 – 1, i.e. 9223372036854775807
Returns: maximum value of Py_ssize_t depending upon the architecture
Example 1: Let us fetch the maximum Py_ssize_t value on a 64-bit system.
Example 2: Creating a list with the maximum size.
9223372036854775807 List succesfully created
Example 3: Trying to create a list with a size greater than the maximum size.
Python int too large to convert to C ssize_t List creation unsuccesful
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course