Modules and Packages
Modules और Packages
What are Modules and Packages?
Modules and Packages means modules are Python files that contain reusable code. Packages are folders that organize multiple modules.
In real programs, this topic helps in using built-in modules. Learn the idea first, then type the program yourself and compare the output.
| Point | Details |
|---|---|
| Course Area | Core Python Basic programming concepts used to write Python programs. |
| Main Use | using built-in modules |
| Example File | modules-packages.py |
| Practice Focus | Run, change values, and explain the output line by line. |
Why should you learn this?
- It is useful for using built-in modules.
- It connects with splitting code into files.
- It improves your ability to read, write and debug Python programs.
Important Terms
These terms are used directly in this lesson. Understand them before memorising the code.
| Term | Meaning |
|---|---|
| import | Keyword used to use code from a module. |
| module | A Python file containing reusable functions, classes or variables. |
| package | A folder containing related modules. |
| library | library is an important term in this topic. |
| reusable code | reusable code is an important term in this topic. |
Syntax / Basic Pattern
The simple pattern is: prepare data, apply the concept, then show the result.
import math
from datetime import date
print("Square root:", math.sqrt(64))
print("Today:", date.today())Complete Example Program
import math
from datetime import date
print("Square root:", math.sqrt(64))
print("Today:", date.today())Expected Output
Program Explanation
import mathimports ready-made features from a module/library.from datetime import dateimports ready-made features from a module/library.print("Square root:", math.sqrt(64))displays information or calculated result on the screen.print("Today:", date.today())displays information or calculated result on the screen.
Where will you use it?
- Using built-in modules.
- Splitting code into files.
- Reusing code from libraries.
Common Mistakes
- Writing code with wrong indentation.
- Using input() value directly in calculations without converting it to int or float.
- Using unclear variable names that make the program difficult to understand.
Practice Tasks
- Type the program in
modules-packages.pyand run it. - Change input values or sample data and observe the new output.
- Create one example related to using built-in modules.
- Write 5 lines explaining the logic in your own words.
Summary
Modules and Packages is not a theory-only topic. You should be able to explain the meaning, write the example, run it successfully, and use it in a small practical program.
Modules और Packages क्या है?
Modules और Packages ka matlab hai: Modules are Python files that contain reusable code. Packages are folders that organize multiple modules. Simple words me, ye topic practical Python programs likhne me direct use hota hai.
Is topic ko sirf definition ke liye nahi, balki using built-in modules jaise real examples ke liye practice karein.
यह क्यों सीखना जरूरी है?
- Ye using built-in modules me kaam aata hai.
- Ye splitting code into files se bhi connected hai.
- Isse aap code ka output aur errors better samajh paate hain.
Important Terms
| Term | Meaning |
|---|---|
| import | Keyword used to use code from a module. |
| module | A Python file containing reusable functions, classes or variables. |
| package | A folder containing related modules. |
| library | library is an important term in this topic. |
| reusable code | reusable code is an important term in this topic. |
Syntax / Basic Pattern
Basic idea: pehle data तैयार करें, phir Python logic apply करें, aur finally result display करें.
import math
from datetime import date
print("Square root:", math.sqrt(64))
print("Today:", date.today())Complete Example Program
import math
from datetime import date
print("Square root:", math.sqrt(64))
print("Today:", date.today())Expected Output
Program Explanation
import mathimports ready-made features from a module/library.from datetime import dateimports ready-made features from a module/library.print("Square root:", math.sqrt(64))displays information or calculated result on the screen.print("Today:", date.today())displays information or calculated result on the screen.
Practical Uses
- Using built-in modules.
- Splitting code into files.
- Reusing code from libraries.
Common Mistakes
- Writing code with wrong indentation.
- Using input() value directly in calculations without converting it to int or float.
- Using unclear variable names that make the program difficult to understand.
Practice Tasks
- Program ko
modules-packages.pyfile me type karke run karein. - Values change karke output compare karein.
- using built-in modules par ek छोटा example banayen.
- Logic ko apne words me 5 lines me likhein.
सारांश
Modules and Packages ko tab complete maanenge jab aap iska meaning, example, output aur practical use clearly explain kar saken.