Important Notice:

Modular Programming and Functions

Modular Programming and Functions

28 views 2 min read

Modular Programming and Functions :- Modular Programming:-

Modular Programming एक Programming Technique है, जिसमें किसी बड़े Program को छोटे-छोटे Independent Parts में Divide किया जाता है। इन Parts को Modules कहा जाता है। प्रत्येक Module एक विशेष Task को Perform करता है और सभी Modules मिलकर पूरे Program को Execute करते हैं।

English Definition:

Modular Programming is a programming technique in which a large program is divided into smaller, independent parts called modules. Each module performs a specific task, and all modules work together to complete the program.

Example:

मान लीजिए हमें Student का Result तैयार करने के लिए एक Program बनाना है। इस Program को निम्नलिखित Modules में Divide किया जा सकता है:

  1. input_marks() — Marks Input करना।

  2. calculate_total() — Total Marks Calculate करना।

  3. calculate_percentage() — Percentage Calculate करना।

  4. display_result() — Result Display करना।

इस प्रकार प्रत्येक Module एक अलग Task करता है।

Important Point: Python में Functions का उपयोग करके Program को छोटे-छोटे Logical Parts में Organize किया जा सकता है। Python में अलग-अलग .py Files भी Modules हो सकती हैं।

Functions as Modules (मॉड्यूल के रूप में फंक्शन्स) :-

Python में Function को Program के एक छोटे Logical Module के रूप में उपयोग किया जा सकता है। प्रत्येक Function एक Specific Task करता है। इससे Program को छोटे और व्यवस्थित Parts में बाँटना आसान होता है।

English Definition:

In Python, a function can be used as a small logical unit of a program. Each function performs a specific task, helping organize a program into smaller and manageable parts.

Syntax

def function_name(parameters):
   statements
   return value

Explanation:

  1. def — Function Define करने के लिए उपयोग होता है।

  2. function_name — Function का नाम होता है।

  3. parameters — वे Variables होते हैं जिनके माध्यम से Function Values प्राप्त कर सकता है।

  4. statements — वे Instructions होते हैं जो Function के Call होने पर Execute होते हैं।

  5. return — Function से Value वापस भेजने के लिए उपयोग होता है। यदि Return की आवश्यकता न हो, तो इसे छोड़ा जा सकता है।

Example

def add(a, b):
    return a + b

def display_result(result):
    print("Sum:", result)

answer = add(10, 20)
display_result(answer)

Output:

Sum: 30

Explanation:

  • add() दो Numbers को जोड़ता है।

  • display_result() प्राप्त Result को Display करता है।

  • दोनों Functions अलग-अलग Tasks करते हैं।

  • दोनों Functions मिलकर Program का कार्य पूरा करते हैं।

Important Point: प्रत्येक Function को एक स्पष्ट और सीमित जिम्मेदारी देना Modular Programming को बेहतर बनाता है।

Related Notes