Home » Python

Sys Module with Examples in Python

Python sys Module: In this tutorial, we are going to learn about the sys module with its functions and examples in Python programming language.
Submitted by Bipin Kumar, on December 11, 2019

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.

Some important function of the sys module

1) sys.version

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)]

2) sys.copyright

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.

3) sys.maxsize

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

4) sys.path

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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.