मैं सत्यम कुमार, आप सभी का एक बार फिर से अपने एक नए पोस्ट (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
Output:
ऊपर दिए गए example में आप साफ़ साफ़ देख सकते है की interpreter के द्वारा comments को ignore कर दिया गया है.
Comments का इस्तेमाल क्यों करते है?
हम python में comments का इस्तेमाल निचे दिए गए कुछ कारण की वजह से करते है:
- Program को clean एवं सरल रखने के लिए.
- अपने द्वारा लिखे गए program को दूसरे को समझाने के लिए.
- अपने program के कुछ महत्पूर्ण भाग या कोड को mark करने के लिए.
Types of Comments In Python
Single line Comments In Python
पाइथन में single line comments hastag symbol से सुरु होता है और इसमें कोई भी whitespace का इस्तेमाल नहीं किया जाता है. ये लाइन के अंत तक चलती है. यदि आपका कमेंट एक लाइन से ज्यादा का है तो आपको अगले लाइन के लिए दुबारा hastag symbol का इस्तेमाल करना पड़ेगा.
अगर आपको अपने प्रोग्राम के किसी भी पार्ट को short में explain करना है तो आप single line comments का इस्तेमाल कर सकता है.
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
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
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
Read more articles: