Important Notice:

Docstrings in Python

Docstrings in Python

4 views 1 min read

Docstrings in Python (पायथन में Docstrings) :-

Docstring (Documentation String) एक विशेष String (स्ट्रिंग) होती है, जिसका उपयोग Module (मॉड्यूल), Function (फ़ंक्शन), Class (क्लास) या Method (मेथड) के बारे में जानकारी (Documentation) लिखने के लिए किया जाता है।

Docstring को Triple Quotes (""" """ या ''' ''') के अंदर लिखा जाता है और इसे संबंधित Module, Function या Class की पहली Statement के रूप में लिखा जाता है।

Python Interpreter Docstring को Comment की तरह Ignore नहीं करता, बल्कि उसे Program की Documentation के रूप में सुरक्षित (Store) रखता है।

Syntax (सिंटैक्स) -

def function_name():
    """Docstring"""
    statements

Example 1: Function Docstring -

def add():
    """This function adds two numbers."""
    print(10 + 20)

add()

English

A Docstring (Documentation String) is a special string used to document a module, function, class, or method.

It is written inside Triple Quotes (""" """ or ''' ''') and must be the first statement inside the module, function, or class.

Unlike comments, Python stores docstrings as documentation.

Syntax (सिंटैक्स) -

def function_name():
    """Docstring"""
    statements

Example 1: Function Docstring -

def add():
    """This function adds two numbers."""
    print(10 + 20)

add()

Related Notes