Key Python Built-in Modules
In programming, a library is a collection of pre-written code that offers reusable functionalities.
A library is composed of various modules, which can work together to perform specific tasks.
Python includes standard libraries such as math and datetime, and the built-in modules within these libraries are provided with Python's installation.
These built-in modules can be used instantly without any additional installation process.
Key Python Built-in Modules
-
math-
Provides functions for mathematical operations.
-
Examples:
math.sqrt(),math.pi,math.sin()
-
-
datetime-
Handles dates and times.
-
Examples:
datetime.datetime.now(),datetime.timedelta()
-
-
os-
Interacts with the operating system and handles the file system.
-
Examples:
os.listdir(),os.path.join()
-
-
sys-
Interacts with the Python interpreter (a program that executes code).
-
Examples:
sys.argv,sys.exit()
-
-
random-
Provides functions for generating random numbers.
-
Examples:
random.randint(),random.choice()
-
-
json-
Parses and generates JSON data.
-
Examples:
json.loads(),json.dumps()
-
-
re-
Handles strings using regular expressions.
-
Examples:
re.match(),re.search()
-
-
urllib-
Used for handling URLs and sending HTTP requests.
-
Example:
urllib.request.urlopen()
-
Built-in Module Usage Example
import math # Calculate the area of a circle radius = 5 area = math.pi * math.pow(radius, 2) print(f"Area of the circle: {area}")
Practice
Click the Run Code button on the right side of the screen to see the result or modify the code!
Lecture
AI Tutor
Help
Code Editor
Execution Result