Python Built-in ModuleLast Updated : 6 Jan 2026 In Python, a module is referred to as a file comprising of functions, classes, or variables. It helps us organizing the code logically and reuse it across different programs. There are many Python modules, each with its specific work. A Python module is a file consisting of Python script (generally, with a .py extension) having definitions of functions, classes, or variables. A module can also include runnable code. Putting related code into a module makes it easier to read, use again in other programs, and keep everything organized. To read more Python Modules ![]() What is Python Built-in Modules?Python Built-in modules are a pre-installed set of libraries. It is quite distracting to install a particular module for a task, as it causes hindrance in the development, so Python comes with some important modules that are most used. These modules play an important role in development as they provide a wide range of functionalities. "os module", "sys module", and "math module" are some examples of built-in modules in Python. Types of Python Built-in Modules1. os ModulePython os module provides the facility to establish the interaction between the user and the operating system. It offers many useful OS functions that are used to perform OS-based tasks and get related information about the operating system. To work with the OS module, we need to import the OS module. To read more Python os Module os Module Functions
2. sys ModuleThe Python sys module provides functions and variables that are used to manipulate different parts of the Python Runtime Environment. It lets us access system-specific parameters and functions. To read more Python sys Module Example: Checking Python Version ExampleCompile and RunOutput: 3.13.7 (tags/v3.13.7:bcee1c3, Aug 14 2025, 14:15:11) [MSC v.1944 64 bit (AMD64)] Explanation The above code prints the value of the version of the Python Interpreter that is currently in use. Importance of the sys module
3. random ModuleIn Python, the Random Module is a built-in module that enables us to generate random numbers. It generates Pseudo-random numbers, which means that those numbers are technically not random. Random objects like numbers, strings, or a list can be generated by the Random Module in Python. To read more Python random Module random Module Functions
4. math ModuleThe Math Module is a built-in module that allows us to use arithmetic operations, complex mathematical calculations like trigonometric functions, logarithms, and exponentials. To read more Python math Module ExampleCompile and RunOutput: Enter a number:25 The square root of the number is: 5.0 Constants in math Module The Math Module in Python provides us with the values of several constants that we regularly use in Mathematical contexts. For example, to find the area of a circle, we have to use pi because the formula is pi*r2, where r is the radius of the circle.
ExampleCompile and RunOutput: Value of Pi Constant 3.141592653589793 Value of Euler's Constant 2.718281828459045 Value of Tau's Constant 6.283185307179586 Value of Infinity = inf Value of Not a Number = nan Python math Module Functions As we know, the Python Math Module allows us to perform advanced mathematical calculations, such as trigonometric functions, logarithms, and exponentials.
5. Python JSON ModuleJSON, which stands for JavaScript Object Notation, is a module that Python offers. Python supports the marshal and pickle modules from the standard library, and JSON API functions similarly to these libraries. Python natively supports JSON characteristics. We can import the JSON module in Python using: ExampleCompile and RunOutput: ['JSONDecodeError', 'JSONDecoder', 'JSONEncoder', '__all__', '__author__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '_default_decoder', '_default_encoder', 'codecs', 'decoder', 'detect_encoding', 'dump', 'dumps', 'encoder', 'load', 'loads', 'scanner'] ExampleCompile and RunOutput:
{"Name" : "Peter", "Roll_no" : "0090014" , "Grade" : "A", "Age" : 20, "Subject" : ["Computer Graphics", "Discrete Mathematics", "Data Structure"] }6. Python datetime ModuleThe datetime module enables us to create custom date objects, perform various operations on dates, like comparison, etc. To work with dates as date objects, we have to import the datetime module into the Python source code. To read more Python datetime Module Consider the following example to get the datetime object representation for the current time. ExampleCompile and RunOutput: 2025-11-04 14:08:00.007276 The datetime classes are classified into six main classes.
How to get the current time? The localtime() functions of the time module are used to get the current time tuple. Consider the following example. Example Output: time.struct_time(tm_year=2020, tm_mon=4, tm_mday=3, tm_hour=21, tm_min=21, tm_sec=40, tm_wday=4, tm_yday=94, tm_isdst=0) 7. calendar ModulePython provides a calendar object that contains various methods to work with calendars. Consider the following example to print the calendar for November month of 2025. ExampleCompile and RunOutput: ![]() Printing Complete Calendar The prcal() method of the calendar module is used to print the calendar of the entire year. The year for which the calendar is to be printed must be passed into this method. ExampleCompile and RunOutput: ![]() 8. tkinter ModuleThe tkinter module is a built-in module. It is the standard GUI toolkit for Python. It is used in desktop applications to design and create buttons, text boxes, windows, and other UI elements. ExampleCompile and RunOutput: ![]() Explanation In the above code, we imported the Tkinter module as tk and defined a class known as click_on_button. We named the title of the dialogue box as Example of using Tkinter Module. The name of the tile is "Example of using Tkinter Module". 9. hashlib moduleThe hashlib module is a built-in module in Python which helpful in hashing by providing algorithms like SHA-256, MD5, etc. It also allows for data integrity checks. ExampleCompile and RunOutput: 006e62197234b1c4c368acbbd705af138f50066c3bf52af64658b6032a4a3314 10. heapq moduleWe can implement the heap queue algorithm by the collection of functions provided by the Heapq module in Python. ExampleCompile and RunOutput: 0 1 [9, 8, 8] [2, 3, 4] Advantages of Built-in Modules
ConclusionIn this tutorial, we learnt about the built-in modules in Python. Python Built-in modules are a pre-installed set of libraries in the Python installation. It is quite distracting to install a particular module for a task, as it causes hindrance in the development, so Python comes with some important modules that are most used. These modules play an important role in development as they provide a wide range of functionalities. We studied in detail the various modules like os, sys, JSON, random, tkinter, math, datetime, calendar, hashlib, and heapq modules. Next TopicPython-split |
We request you to subscribe our newsletter for upcoming updates.