The Wayback Machine - https://web.archive.org/web/20241118044503/https://www.geeksforgeeks.org/sys-maxsize-in-python/
Open In App

sys.maxsize in Python

Last Updated : 17 May, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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

sys.maxsize

Syntax: sys.maxsize

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.

Python
# importing the module
import sys
      
# fetching the maximum value
max_val = sys.maxsize
print(max_val)

Output:

9223372036854775807

Example 2: Creating a list with the maximum size.

Python
# importing the module
import sys
      
# fetching the maximum value
max_val = sys.maxsize

# creating list with max size
list = range(max_val)

# displaying the length of the list
print(len(list))

print("List successfully created")

Output
9223372036854775807
List successfully created

Example 3: Trying to create a list with a size greater than the maximum size.

Python
# importing the module
import sys
      
# fetching the maximum value
max_val = sys.maxsize

try:

    # creating list with max size + 1
    list = range(max_val + 1)

    # displaying the length of the list
    print(len(list))
    print("List successfully created")
    
except Exception as e:

    # displaying the exception
    print(e)
    print("List creation unsuccessful")

Output
Python int too large to convert to C ssize_t
List creation unsuccessful


Similar Reads

maxsize() method in Tkinter | Python
This method is used to set the maximum size of the root window (maximum size a window can be expanded). User will still be able to shrink the size of the window to the minimum possible. Syntax : master.maxsize(height, width) Here, height and width are in pixels. Code #1: C/C++ Code # importing only those functions # which are needed from tkinter im
2 min read
Python - sys.settrace()
Python sys module provides some of the powerful functions but they are complex to understand. One of which is the sys.settrace() which is used for implementing debuggers, profilers and coverage tools. This is thread-specific and must register the trace using threading.settrace(). Knowing how the function works internally is really important in case
3 min read
Python | sys.getallocatedblocks() method
This sys module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It provides information about constants, functions and methods of python interpreter. It can be used for manipulating Python runtime environment. sys.getallocatedblocks() is used to get number of memo
1 min read
Python | sys.getrecursionlimit() method
This sys module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It provides information about constants, functions and methods of python interpreter. It can be used for manipulating Python runtime environment. sys.getrecursionlimit() method is used to find the cur
1 min read
Python | sys.getdefaultencoding() method
This sys module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It provides information about constants, functions and methods of python interpreter. It can be used for manipulating Python runtime environment. sys.getdefaultencoding() method is used to get the cur
1 min read
Python | sys.setrecursionlimit() method
This sys module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It provides information about constants, functions and methods of python interpreter. It can be used for manipulating Python runtime environment. sys.setrecursionlimit() method is used to set the maxi
2 min read
Python | sys.setswitchinterval() method
This sys module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It provides information about constants, functions and methods of python interpreter. It can be used for manipulating Python runtime environment. sys.setswitchinterval() method is used to set the inte
2 min read
Python | sys.getswitchinterval() method
This sys module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It provides information about constants, functions and methods of python interpreter. It can be used for manipulating Python runtime environment. sys.getswitchinterval() method is used to get the inte
1 min read
Python - sys.stdout.flush()
A data buffer is a region of physical memory storage used to temporarily store data while it is being moved from one place to another. The data is stored in a buffer as it is retrieved from an input device or just before it is sent to an output device or when moving data between processes within a computer. Python's standard out is buffered. This m
3 min read
sys.stdout.write in Python
This is a built-in Python module that contains parameters specific to the system i.e. it contains variables and methods that interact with the interpreter and are also governed by it. sys.stdout A built-in file object that is analogous to the interpreter's standard output stream in Python. stdout is used to display output directly to the screen con
2 min read
Python sys Module
The sys module in Python provides various functions and variables that are used to manipulate different parts of the Python runtime environment. It allows operating on the interpreter as it provides access to the variables and functions that interact strongly with the interpreter. Let's consider the below example. Sys Module in PythonPython sys.ver
6 min read
How to use sys.argv in Python
Command line arguments are those values that are passed during calling of program along with the calling statement. Thus, the first element of the array sys.argv() is the name of the program itself. sys.argv() is an array for command line arguments in Python. To employ this module named " sys " is used. sys.argv is similar to an array and the value
3 min read
Python exit commands: quit(), exit(), sys.exit() and os._exit()
The functions quit(), exit(), sys.exit(), and os._exit() have almost the same functionality as they raise the SystemExit exception by which the Python interpreter exits and no stack traceback is printed. We can catch the exception to intercept early exits and perform cleanup activities; if uncaught, the interpreter exits as usual. In this article,
6 min read
sys.path in Python
Sys is a built-in Python module that contains parameters specific to the system i.e. it contains variables and methods that interact with the interpreter and are also governed by it.  sys.pathsys.path is a built-in variable within the sys module. It contains a list of directories that the interpreter will search in for the required module.  When a
4 min read
sys.maxint in Python
In programming, maxint/INT_MAX denotes the highest value that can be represented by an integer. In some cases, while programming, we may need to assign a value that is larger than any other integer value. Normally one assigns such values manually. For example, consider a list of integers where the minimum value has to be found out using a for loop.
4 min read
Difference between input() and sys.stdin.readline()
Python is a widely used general-purpose language that can be used for many purposes. Taking input in any language is as important as breathing for humans. Python provides various methods for taking input. However, we all may get confused about how each method is different from one another. In this article, we will discuss about two such methods i.e
2 min read
Important differences between Python 2.x and Python 3.x with examples
In this article, we will see some important differences between Python 2.x and Python 3.x with the help of some examples. Differences between Python 2.x and Python 3.x Here, we will see the differences in the following libraries and modules: Division operatorprint functionUnicodexrangeError Handling_future_ modulePython Division operatorIf we are p
5 min read
Reading Python File-Like Objects from C | Python
Writing C extension code that consumes data from any Python file-like object (e.g., normal files, StringIO objects, etc.). read() method has to be repeatedly invoke to consume data on a file-like object and take steps to properly decode the resulting data. Given below is a C extension function that merely consumes all of the data on a file-like obj
3 min read
Python | Add Logging to a Python Script
In this article, we will learn how to have scripts and simple programs to write diagnostic information to log files. Code #1 : Using the logging module to add logging to a simple program import logging def main(): # Configure the logging system logging.basicConfig(filename ='app.log', level = logging.ERROR) # Variables (to make the calls that follo
2 min read
Python | Add Logging to Python Libraries
In this article, we will learn how to add a logging capability to a library, but don’t want it to interfere with programs that don’t use logging. For libraries that want to perform logging, create a dedicated logger object, and initially configure it as shown in the code below - Code #1 : C/C++ Code # abc.py import logging log = logging.getLogger(_
2 min read
Python | Index of Non-Zero elements in Python list
Sometimes, while working with python list, we can have a problem in which we need to find positions of all the integers other than 0. This can have application in day-day programming or competitive programming. Let's discuss a shorthand by which we can perform this particular task. Method : Using enumerate() + list comprehension This method can be
6 min read
MySQL-Connector-Python module in Python
MySQL is a Relational Database Management System (RDBMS) whereas the structured Query Language (SQL) is the language used for handling the RDBMS using commands i.e Creating, Inserting, Updating and Deleting the data from the databases. SQL commands are case insensitive i.e CREATE and create signify the same command. In this article, we will be disc
2 min read
Python - Read blob object in python using wand library
BLOB stands for Binary Large OBject. A blob is a data type that can store binary data. This is different than most other data types used in databases, such as integers, floating point numbers, characters, and strings, which store letters and numbers. BLOB is a large complex collection of binary data which is stored in Database. Basically BLOB is us
2 min read
twitter-text-python (ttp) module - Python
twitter-text-python is a Tweet parser and formatter for Python. Amongst many things, the tasks that can be performed by this module are : reply : The username of the handle to which the tweet is being replied to. users : All the usernames mentioned in the tweet. tags : All the hashtags mentioned in the tweet. urls : All the URLs mentioned in the tw
3 min read
Reusable piece of python functionality for wrapping arbitrary blocks of code : Python Context Managers
Context Managers are the tools for wrapping around arbitrary (free-form) blocks of code. One of the primary reasons to use a context manager is resource cleanliness. Context Manager ensures that the process performs steadily upon entering and on exit, it releases the resource. Even when the wrapped code raises an exception, the context manager guar
7 min read
Creating and updating PowerPoint Presentations in Python using python - pptx
python-pptx is library used to create/edit a PowerPoint (.pptx) files. This won't work on MS office 2003 and previous versions. We can add shapes, paragraphs, texts and slides and much more thing using this library. Installation: Open the command prompt on your system and write given below command: pip install python-pptx Let's see some of its usag
4 min read
Python Debugger – Python pdb
Debugging in Python is facilitated by pdb module (python debugger) which comes built-in to the Python standard library. It is actually defined as the class Pdb which internally makes use of bdb(basic debugger functions) and cmd (support for line-oriented command interpreters) modules. The major advantage of pdb is it runs purely in the command line
5 min read
Filter Python list by Predicate in Python
In this article, we will discuss how to filter a python list by using predicate. Filter function is used to filter the elements in the given list of elements with the help of a predicate. A predicate is a function that always returns True or False by performing some condition operations in a filter method Syntax: filter(predicate, list) where, list
2 min read
Python: Iterating With Python Lambda
In Python, the lambda function is an anonymous function. This one expression is evaluated and returned. Thus, We can use lambda functions as a function object. In this article, we will learn how to iterate with lambda in python. Syntax: lambda variable : expression Where, variable is used in the expressionexpression can be an mathematical expressio
2 min read
Python Value Error :Math Domain Error in Python
Errors are the problems in a program due to which the program will stop the execution. One of the errors is 'ValueError: math domain error' in Python. In this article, you will learn why this error occurs and how to fix it with examples. What is 'ValueError: math domain error' in Python?In mathematics, we have certain operations that we consider un
4 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg