Modules and Package in python (2)
Modules and Package in python (2)
Modules in Python
What is a Module?
1. Create a Module:
Create a file named math_utils.py and add the following code:
# math_utils.py
# main.py
import math_utils
result_add = math_utils.add(5, 3)
result_subtract = math_utils.subtract(5, 3)
○
3. Importing Specific Functions:
# main.py
result_add = add(5, 3)
result_subtract = subtract(5, 3)
Packages in Python
What is a Package?
math_utils.py:
# math_utils.py
# string_utils.py
# main.py
result_add = math_utils.add(5, 3)
result_subtract = math_utils.subtract(5, 3)
result_concat = string_utils.concatenate("Hello", "World")
result_split = string_utils.split_string("Hello World")
Data Analysis
1. Pandas:
○ Provides high-performance data structures and data analysis
tools.
Example:
import pandas as pd
2. NumPy:
○ Supports large, multi-dimensional arrays and matrices, along
with mathematical functions.
Example:
import numpy as np
array = np.array([1, 2, 3, 4])
print(array)
Web Development
1. Flask:
○ A lightweight web framework for building web applications.
Example:
app = Flask(__name__)
@app.route('/')
def home():
return "Hello, Flask!"
if __name__ == '__main__':
app.run(debug=True)
2. Django:
○ A high-level web framework that encourages rapid development
and clean design.
Example:
plaintext
# Command Line Instructions:
# django-admin startproject myproject
# cd myproject
# python manage.py