What are Comments In Python and How to Write Comments In Python?

मैं सत्यम कुमार, आप सभी का एक बार फिर से अपने एक नए पोस्ट (Comments in python) में स्वागत करता हूँ. इस पोस्ट में मैं आपको बताने वाला हूँ की कमैंट्स क्या होता है और पाइथन में कमैंट्स कैसे लिखा जाता है.

comments in python

What are Comments In Python?

Comments किसी program के ऐसे codes होते है जो की interpreter के द्वारा execution के टाइम पर ignore कर दिए जाते है.  इस तरह के codes आपके प्रोग्राम के output को किसी भी तरीके से affect नहीं करते है. Comments का इस्तेमाल हम कोड को अच्छे से समझने या समझाने के लिए करते है.

Python में दो तरह के comments होते है:

  • Single line Comments
  • Multiline Comments

Example: Comments in Python

comments in python

Output:

comments in python

ऊपर दिए गए example में आप साफ़ साफ़ देख सकते है की interpreter के द्वारा comments को ignore कर दिया गया है.

Comments का इस्तेमाल क्यों करते है?

हम python में comments का इस्तेमाल निचे दिए गए कुछ कारण की वजह से करते है:

  • Program को clean एवं सरल रखने के लिए.
  • अपने द्वारा लिखे गए program को दूसरे को समझाने के लिए.
  • अपने program के कुछ महत्पूर्ण भाग या कोड को mark करने के लिए.

Types of Comments In Python

types of comments in python

Single line Comments In Python

पाइथन में single line comments hastag symbol से सुरु होता है और इसमें कोई भी whitespace का इस्तेमाल नहीं किया जाता है. ये लाइन के अंत तक चलती है. यदि आपका कमेंट एक लाइन से ज्यादा का है तो आपको अगले लाइन के लिए दुबारा hastag symbol का इस्तेमाल करना पड़ेगा.

अगर आपको अपने प्रोग्राम के किसी भी पार्ट को short में explain करना है तो आप single line comments का इस्तेमाल कर सकता है.

comments in python

Multiline Comments In Python

जब हम अपने प्रोग्राम में एक से ज्यादा लाइन का comments लिखते है तो उसे हम multiline comments कहते है. Python में multiline comments लिखने के कुछ तरीके:

1. एक से ज्यादा हस्टाग सिंबल के इस्तेमाल से 

Example:

#welcome to hinditechclub.com

#this is a multiline comment

#interpreter will ignore this

print(“I am a multiline comment”)

Output: I am a multiline comment

 comments in python

2. Triple quote के इस्तेमाल से

Example:

”’ Welcome to hinditechclub.com

This is a multiline comment and it

will be ignored by the interpreter.”’

print(“I am a Multiline comment”)

Output: I am a Multiline comment

comments in python

3. Triple double quote के इस्तेमाल से 

Example:

“””Welcome to hinditechclub.com

This is a multiline comment and it

will be ignored by the interpreter”””

print(“Multiline comments”)

Output: Multiline comments

comments in python


Read more articles:

Leave a Comment