Show7_Pro

🟢 Lesson 6 – Intermediate Level

🔰 What Is a Module?

The current image has no alternative text. The file name is: Show.jpg

A module is simply a Python file (.py) containing code (functions, variables, classes) you can reuse in other programs.

Python has:

  • Built-in modules (already included with Python, like math, random, os)
  • External libraries (installed with pip, like requests, pandas)
  • Custom modules (your own .py files)

📦 Importing a Module

pythonCopierModifierimport math

print(math.sqrt(25))  # Output: 5.0

🎯 Importing Specific Functions

pythonCopierModifierfrom math import sqrt, pi

print(sqrt(49))   # Output: 7.0
print(pi)         # Output: 3.141592653589793

✍️ Creating Your Own Module

  1. Create a file called mymodule.py:
pythonCopierModifierdef greet(name):
    return f"Hello, {name}!"

pi_value = 3.1416
  1. In another Python file:
pythonCopierModifierimport mymodule

print(mymodule.greet("Ali"))
print(mymodule.pi_value)

📚 Installing External Libraries with pip

Example: Install and Use requests

  1. In your terminal or command prompt:
bashCopierModifierpip install requests
  1. In Python:
pythonCopierModifierimport requests

response = requests.get("https://api.github.com")
print(response.status_code)

🔍 Popular Python Libraries

LibraryPurpose
mathMathematical functions
randomRandom number generation
osInteract with the operating system
datetimeDates and times
requestsHTTP requests (APIs, web data)
pandasData analysis
numpyNumerical computing

🧠 Exercise 1: Using a Built-in Module

  1. Import the random module.
  2. Generate 5 random integers between 1 and 50.
pythonCopierModifierimport random

for i in range(5):
    print(random.randint(1, 50))

🧠 Exercise 2: Create and Import Your Module

  • Create a module calculator.py with:
    • add(a, b)
    • subtract(a, b)
  • Import and use it in another script.

📝 Summary

  • Modules let you reuse and organize your code.
  • Use import to bring in Python’s built-in modules.
  • Use pip install to add external libraries.
  • You can write your own modules for personal or team projects.
⬇️ Download Show7_Pro تحميل Server 1 ⬇️ Download Show7_Pro تحميل Server 2 ⬇️ Download Show7_Pro تحميل Server 3

Related Posts

FlyFeditv

📘 Introduction In this project, you’ll create a command-line Expense Tracker that allows users to: ✅ Add expenses with category, amount, and description✅ View total spending and category breakdown✅ Automatically…

Read more

NetCinFly

📘 Introduction In this project, you’ll develop a Student Grades Analyzer in Python that can: This project helps you strengthen your skills with lists, dictionaries, loops, and data analysis logic….

Read more

Eagle_Pro

🌐 Introduction In this project, you’ll create a Web Scraper App in Python that extracts quotes, authors, and tags from a live website.You’ll use the BeautifulSoup and Requests libraries to…

Read more

Cobra_Pro

🌦️ Introduction In this project, you’ll build a Weather App in Python that retrieves live weather information from an online API.You’ll learn how to work with HTTP requests, JSON data,…

Read more

Show7-Pro

Concepts Covered: 🎯 Objective: Create a simple, text-based contact book application that allows users to: 💡 Code (contact_book.py): 🧠 Example Usage Console Output Example: 💾 Notes ⬇️ Download Show7-Pro تحميل…

Read more

Rapid_tv

🔹 Introduction The Rock, Paper, Scissors Game is a classic hand game that you can easily build in Python. 👉 Rules: 🔹 Code Example 🔹 Example Run 🔹 Concepts Learned…

Read more