WhatsApp

Stay Connected with PythonHindii

Join our WhatsApp Community to get the latest Python tutorials, coding tips, interview questions, project updates, and learning resources directly on your phone.

Join WhatsApp Community
Python Hindi Logo
Python in Hindi | Programming Education
Join Karo
Python programming tutorial in Hindi banner Python code learning illustration Hindi Python student coding illustration Python data code pattern background

Python Tutorial in HindiiLearn Python Programming for Free

Learn Python from Beginner to Advanced in simple Hindi.

💰 100% Free 🌐 Hindi Mein 📱 WhatsApp Community 🔄 Weekly Updates
print("Namaste Python!")
# Variable banana
naam = "Ankit"
umar = 25
 
for i in range(3):
  print("Sikho!")
 
# Output:
Sikho! Sikho! Sikho!

Ye Kaise Kaam Karta Hai

Hindi mein Python, AI aur Data Skills seekhne ka sabse simple tareeka.

📘

Seekhein

Beginner se Advanced tak, best curated tutorials aur guides Hindi mein.

💻

Practice Karein

Real code examples aur mini-projects ke through hands-on practice karein.

💬

Judein

WhatsApp community se judkar apne doubts clear karein, akele nahi seekhenge.

Python में Multiline Comments कैसे लिखें – पूरी जानकारी हिंदी में

Python multiline comment example hindi

                     Multiline comment Python का वो comment होता है जो एक line में खत्म नहीं होता, बल्कि कई lines तक फैला रहता है। इसका इस्तेमाल तब होता है जब code को detail में explain करना हो, किसी बड़े हिस्से को temporarily disable करना हो, या फिर readability बढ़ानी हो। Python में इसके लिए कोई अलग से keyword नहीं दिया गया, लेकिन developers चार अलग-अलग तरीकों से यह काम निकाल लेते हैं।

यह comments code को समझने में आसानी देते हैं, documentation का काम करते हैं, team collaboration बेहतर बनाते हैं और debugging में भी मदद करते हैं।

Multiline Comments लिखने के तरीके

1. # Symbol वाला तरीका

                    यह सबसे common और सबसे ज्यादा recommend किया जाने वाला तरीका है। बस हर नई line के शुरुआत में # लगा दीजिए, Python interpreter उस पूरी line को skip कर देगा।

# यह एक multiline comment है
# हर line अलग से शुरू होती है #
# यह तरीका सबसे efficient माना जाता है

print("Namaste Python")  # यह inline comment है

Output:

Namaste Python

             Explanation: ऊपर तीनों # वाली lines को interpreter पूरी तरह ignore कर देता है, इसलिए वो execute नहीं होतीं। सिर्फ print statement चलता है और अंत में # के बाद लिखा inline comment भी छोड़ दिया जाता है।

2. Triple Quotes (''' या """) वाला तरीका

                     Python में तीन single quotes या तीन double quotes के बीच लिखा text multi-line string बन जाता है। अगर उसे किसी variable में assign नहीं किया जाए, तो वो सिर्फ बनकर रह जाता है और execute नहीं होता, यानी practically comment जैसा behave करता है।

'''
यह triple single quotes से बना
multiline comment है
'''

print("Triple Quotes Example")

"""
यह triple double quotes वाला
दूसरा तरीका है
"""

Output:

Triple Quotes Example

                 Explanation: दोनों triple-quoted blocks किसी variable में store नहीं हुए, इसलिए Python उन्हें बना तो देता है लेकिन उनका कोई असर code पर नहीं पड़ता। यह तरीका सबसे ज्यादा docstrings के लिए इस्तेमाल होता है, comments के लिए कम।

3. Backslash (\) वाला तरीका

                 यह तरीका थोड़ा कम जाना-पहचाना है। Backslash (\) असल में line continuation के लिए बना है, यानी एक statement को अगली line तक बढ़ाने के लिए। कई developers इसे # comments के साथ मिलाकर एक creative workaround की तरह इस्तेमाल करते हैं, जिससे लगातार कई lines पर comment जैसा असर दिखे।

# Backslash की मदद से multiline comment जैसा असर \
# यह एक साथ जुड़ी हुई lines जैसा दिखता है \
# लेकिन असल में यह line continuation है

print("Backslash Method Example")

Output:

Backslash Method Example

                  Explanation: यहां backslash हर line को अगली line से जोड़ने का काम करता है, लेकिन चूंकि हर line पहले से # से शुरू होती है, इसलिए interpreter उसे comment मानकर ही छोड़ देता है। यह तरीका ना तो सबसे साफ है और ना ही सबसे ज्यादा इस्तेमाल होता है, लेकिन जानना ज़रूरी है।

4. Docstrings वाला तरीका

                        जब triple quotes किसी function, class या module के सबसे पहले statement के रूप में लिखे जाते हैं, तो वो सिर्फ comment नहीं रहते बल्कि docstring बन जाते हैं। यह Python की metadata की तरह store होते हैं और .__doc__ attribute से runtime पर भी पढ़े जा सकते हैं।

def add_numbers(a, b):
    """
    यह function दो numbers को जोड़ता है
    और उनका result return करता है
    """
    return a + b

print(add_numbers.__doc__)

Output:

यह function दो numbers को जोड़ता है
और उनका result return करता है

               Explanation: Docstring function के अंदर first statement की तरह लिखा गया, इसलिए Python इसे automatically function की documentation मान लेता है। add_numbers.__doc__ लिखते ही वही text वापस मिल जाता है, जो साधारण comment के साथ कभी नहीं होता।

Docstring और Multiline Comment में फर्क

FeatureMultiline CommentDocstring
मकसदcode explain करनाfunction/class/module document करना
Syntaxहर line पर # या unassigned triple quotesfunction/class के पहले statement के रूप में triple quotes
Executionपूरी तरह ignore हो जाता हैstring के रूप में store रहता है
कहां लिखेंcode में कहीं भीसिर्फ function, class या module के शुरुआत में
Accessruntime पर access नहीं होता.__doc__ या help() से access होता है
Best Practiceactual comments के लिए # इस्तेमाल करेंdocumentation के लिए triple quotes इस्तेमाल करें

Debugging में Multiline Comments का इस्तेमाल

                 Debugging के समय अक्सर code के कुछ हिस्सों को temporarily बंद करना पड़ता है, ताकि पता चल सके कि problem कहां से आ रही है।

# print("यह line अभी नहीं चलेगी")
# print("इसे testing के लिए बंद किया गया है")

'''
print("यह पूरा block भी फिलहाल off है")
'''

print("बाकी सब कुछ normal चल रहा है")

Explanation:

  • Code को temporarily disable करने के लिए यह तरीका काफी काम आता है
  • # वाले comments debugging के लिए ज्यादा safe माने जाते हैं
  • Triple-quoted strings को debugging के लिए बार-बार इस्तेमाल करने से बचना चाहिए

                   Note: Google Colab या Jupyter Notebook जैसी जगहों पर अगर triple-quoted string किसी cell की last line हो, तो वो output की तरह print हो सकती है, भले ही आपने print() ना लिखा हो। Normal .py script में ऐसा नहीं होता, वहां print() लिखना ही पड़ता है।

(Related Articles)

Python Tutorial in Hindi

Python Data Types in Hindi

Python Install Kaise Karein

Python Cheat Sheet in Hindi

MySQL Tutorial in Hindi

AI Tutorials in Hindi

Data Analyst Tutorial in Hindi

FAQ

अक्सर पूछे जाने वाले सवाल (FAQ)

Python में multiline comment के लिए कितने तरीके हैं

मुख्य रूप से चार तरीके इस्तेमाल किए जाते हैं – हर line पर # लगाना, unassigned triple-quoted string, backslash continuation के साथ # comments, और docstring।

कौन सा तरीका सबसे ज्यादा recommend किया जाता है

PEP 8 के अनुसार हर line पर # लगाना सबसे Pythonic और साफ तरीका माना जाता है, खासकर debugging और actual comments के लिए।

Docstring को .__doc__ से क्यों access किया जा सकता है

क्योंकि docstring किसी function, class या module के पहले statement के रूप में लिखा गया triple-quoted string होता है, जिसे Python automatically उस object की metadata के रूप में store कर लेता है।

क्या triple-quoted comment हर जगह सुरक्षित है

नहीं, notebooks जैसे Google Colab या Jupyter में अगर यह किसी cell की last line हो, तो वो output के रूप में print हो सकता है, इसलिए वहां सावधानी से इस्तेमाल करना चाहिए।

PYTHONHINDII.IN
1 / 5
Suggested Quiz

🎓 Recommended Python Courses (Hindi mein sikho)