🟢 Beginner  ·  Lesson 17

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.

💡 At a Glance
PointDetails
Course AreaCore Python
Basic programming concepts used to write Python programs.
Main Useusing built-in modules
Example Filemodules-packages.py
Practice FocusRun, 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.

TermMeaning
importKeyword used to use code from a module.
moduleA Python file containing reusable functions, classes or variables.
packageA folder containing related modules.
librarylibrary is an important term in this topic.
reusable codereusable code is an important term in this topic.

Syntax / Basic Pattern

The simple pattern is: prepare data, apply the concept, then show the result.

Basic Pattern
import math
from datetime import date
print("Square root:", math.sqrt(64))
print("Today:", date.today())

Complete Example Program

Python – modules-packages.py
import math
from datetime import date

print("Square root:", math.sqrt(64))
print("Today:", date.today())

Expected Output

Square root: 8.0 Today: YYYY-MM-DD

Program Explanation

  • import math imports ready-made features from a module/library.
  • from datetime import date imports 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

  1. Type the program in modules-packages.py and run it.
  2. Change input values or sample data and observe the new output.
  3. Create one example related to using built-in modules.
  4. 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

TermMeaning
importKeyword used to use code from a module.
moduleA Python file containing reusable functions, classes or variables.
packageA folder containing related modules.
librarylibrary is an important term in this topic.
reusable codereusable code is an important term in this topic.

Syntax / Basic Pattern

Basic idea: pehle data तैयार करें, phir Python logic apply करें, aur finally result display करें.

Basic Pattern
import math
from datetime import date
print("Square root:", math.sqrt(64))
print("Today:", date.today())

Complete Example Program

Python – modules-packages.py
import math
from datetime import date

print("Square root:", math.sqrt(64))
print("Today:", date.today())

Expected Output

Square root: 8.0 Today: YYYY-MM-DD

Program Explanation

  • import math imports ready-made features from a module/library.
  • from datetime import date imports 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

  1. Program ko modules-packages.py file me type karke run karein.
  2. Values change karke output compare karein.
  3. using built-in modules par ek छोटा example banayen.
  4. 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.

← Back to Python Tutorial