0% found this document useful (0 votes)
3 views11 pages

Python Modules and Built-in Libraries Guide

Uploaded by

Meghana K S
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views11 pages

Python Modules and Built-in Libraries Guide

Uploaded by

Meghana K S
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Python Modules, Packages, and

Built-in Libraries
Module 1 - Simple Module
• [Link]
• def add(a, b):
• return a + b

• def subtract(a, b):


• return a - b

• Usage:
• import calculator
• print([Link](5, 3))
• print([Link](5, 3))
Module 2 - Math Module
• import math
• print("Square root of 16:", [Link](16))
• print("Value of pi:", [Link])
Module 3 - Package Example
• Folder Structure:
• mypackage/
• __init__.py
• [Link]
• [Link]

• [Link]
• def multiply(a, b):
• return a * b

• [Link]
• def greet(name):
• return f"Hello, {name}!"

• Usage:
• from mypackage import operations, utils
• print([Link](4, 5))
• print([Link]("Alice"))
Module 4 - Renaming Module
• import math as m
• print("Square root of 25:", [Link](25))
Module 5 - Reload Module
• import mymodule
• import importlib
• [Link](mymodule)
Built-in Library 1 - os Module
• import os
• print("Current working directory:",
[Link]())
Built-in Library 2 - sys Module
• import sys
• print("Python version:", [Link])
Built-in Library 3 - random Module
• import random
• print("Random number between 1 and 10:",
[Link](1, 10))
Built-in Library 4 - datetime Module
• import datetime
• now = [Link]()
• print("Current date and time:", now)
Built-in Library 5 - time Module
• import time
• start_time = [Link]()
• [Link](2)
• end_time = [Link]()
• print("Elapsed time:", end_time - start_time,
"seconds")

You might also like