Python sys Module with Examples

Python sys Module: In this tutorial, we are going to learn about the sys module with its functions and examples in Python programming language. By Bipin Kumar Last updated : June 21, 2023

Python sys Module

The sys module provides us the information about the Python interpreter that is used to interact with the Python interpreter. This module is one of the best modules of Python and to use the sys module, we have to import it in the program like other inbuilt modules. This provides a lot of information about the Python interpreter such as the version of the interpreter, the max value that a variable can store, information about the copyright of the Python interpreter, etc. Here, we will see some important functions of the sys module with an example.

Most Useful Methods of Python sys Module

sys.version() Method

This function returns a string representing the version of the Python interpreter with the date of the installation.

Example

# Importing the module
import sys

# Printing the python version
print(sys.version)

Output

3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)]

sys.copyright() Method

This function returns information about the copyright of the Python interpreter.

Example

# Importing the module
import sys

# Printing the copyright information
print('Information about the copyright:')
print(sys.copyright)

Output

Information about the copyright:Copyright (c) 2001-2019 Python Software Foundation.
All Rights Reserved.

Copyright (c) 2000 BeOpen.com.
All Rights Reserved.

Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All Rights Reserved.

Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved.

sys.maxsize() Method

This function returns the maximum value of integer that a variable can take.

Example

# Importing the module
import sys

# Printing the max value of an integer
print('Maximum value of an integer:',sys.maxsize)

Output

Maximum value of an integer: 9223372036854775807

sys.path() Method

This function returns a list that contains the search path for all Python modules.

Example

# Importing the module
import sys

# Printing the all path
print('List of the all path:')
print(sys.path)

Output

List of the all path:['/home/runner', '/usr/local/lib/python37.zip', 
'/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', 
'/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages']

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.