Modules in Python
- A module in Python is a file containing Python definitions and statements. It allows you to organize your code into reusable components.
Syntax:
# Importing a module
import module_name
Example:
Importing Modules
- Importing modules makes functions, variables, and classes defined in them available for use in your program.
Syntax:
import module_name
Example:
What is a Custom Module?
- A custom module is simply a Python file (ending in .py) that contains functions, variables, or classes that you create. This allows you to organize your code into separate files and reuse them easily.
Steps to Create and Use a Custom Module:
1. Create a Python File (Module) :
- First, create a Python file (e.g., my_module.py) where you define your functions or variables.
3. math Module
- The math module provides mathematical functions, like trigonometric operations, logarithmic functions, etc.
Syntax:
import math
Example:
0 Comments