Introduction To Python (Chapter: 3) | EduNotes

Programming Paradigms in Python

Programming Paradigms in Python

Programming Paradigm ka matlab hota hai program likhne ka style ya approach. Ye batata hai ki programmer computer ko problem solve karne ke liye kaise instructions deta hai.

Python ek multi-paradigm language hai, matlab Python me ek se zyada programming styles use kiye ja sakte hain.

1. Imperative Paradigm (How to do the task)

Imperative Paradigm me hum computer ko step-by-step batate hain ki kaam kaise karna hai.

  • Focus hota hai HOW task perform hoga
  • Variables, loops aur conditions ka use hota hai
  • Program ka control flow clearly defined hota hai

Simple Meaning:

Computer ko exact instructions dena –
“Pehle ye karo, phir ye, phir ye…”

Example (Imperative Style)
Task: Numbers ki list ka sum nikalna

numbers = [1, 2, 3, 4]
total = 0

for n in numbers:
    total = total + n

print(total)
  

Explanation:

  • total = 0 se start kiya
  • Loop chalaya
  • Har number ko manually add kiya
  • Har step clearly define hai

Isi wajah se ise Imperative Programming kehte hain.

Where Imperative Paradigm is Used:

  • Basic Python programs
  • Loops (for, while)
  • Conditional statements (if-else)
  • Beginners ke liye best approach

2. Declarative Paradigm (What result is needed)

Declarative Paradigm me hum computer ko ye nahi batate ki kaam kaise karna hai, balki sirf ye batate hain ki final result kya chahiye.

  • Focus hota hai WHAT result chahiye
  • Steps internally language handle karti hai
  • Code short aur readable hota hai

Simple Meaning:

Computer se kehna –
“Mujhe ye result chahiye, tum khud decide karo kaise karna hai”

Example (Declarative Style)
Same Task: Numbers ki list ka sum nikalna

numbers = [1, 2, 3, 4]
total = sum(numbers)
print(total)
  

Explanation:

  • Hume loop likhne ki zarurat nahi
  • sum() function internally sab handle karta hai
  • Code simple aur clean hota hai

Isi wajah se ise Declarative Programming kehte hain.

Where Declarative Paradigm is Used:

  • Built-in functions (sum(), max(), min())
  • List comprehension
  • Functional programming style
  • Data processing

Imperative vs Declarative (Quick Comparison)

Imperative Paradigm Declarative Paradigm
HOW pe focus WHAT pe focus
Step-by-step instructions Result-oriented
Code thoda long Code short aur clean
Beginner friendly Readability ke liye best

Important Student Note

  • Python dono paradigms support karta hai
  • Beginners pehle Imperative style seekhte hain
  • Advanced Python me Declarative style zyada use hota hai
  • Real projects me dono ka mix hota hai