Docstrings

इंटरमीडिएट Python फॉर डेवलपर्स

Jasmin Ludolf

Senior Data Science Content Developer

Docstrings

  • किसी फंक्शन का वर्णन करने वाला टेक्स्ट ब्लॉक

  • उपयोगकर्ताओं को फंक्शन का उपयोग समझाने में मदद करें

Help on built-in function round in module builtins:

round(number, ndigits=None)

Round a number to a given precision in decimal digits. The return value is an integer if ndigits is omitted or None. Otherwise the return value has the same type as the number. ndigits may be negative.
इंटरमीडिएट Python फॉर डेवलपर्स

Docstring एक्सेस करना

# जानकारी एक्सेस करें, जिसमें docstring शामिल है
print(help(round))
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None.  Otherwise
    the return value has the same type as the number.  ndigits may be negative.

None
इंटरमीडिएट Python फॉर डेवलपर्स

Docstring एक्सेस करना

# केवल docstring एक्सेस करें
print(round
इंटरमीडिएट Python फॉर डेवलपर्स

Docstring एक्सेस करना

# केवल docstring एक्सेस करें
print(round.
इंटरमीडिएट Python फॉर डेवलपर्स

Docstring एक्सेस करना

# केवल docstring एक्सेस करें
print(round.__
इंटरमीडिएट Python फॉर डेवलपर्स

Docstring एक्सेस करना

# केवल docstring एक्सेस करें
print(round.__doc
इंटरमीडिएट Python फॉर डेवलपर्स

Docstring एक्सेस करना

# केवल docstring एक्सेस करें
print(round.__doc__)
Round a number to a given precision in decimal digits.

The return value is an integer if ndigits is omitted or None.  Otherwise
the return value has the same type as the number.  ndigits may be negative.

$$

$$

  • .__doc__: "dunder-doc" एट्रिब्यूट
इंटरमीडिएट Python फॉर डेवलपर्स

Docstring बनाना

def average(values):

# एक-पंक्ति docstring """मानों के अनुक्रम का औसत निकालें और दो दशमलव तक राउंड करें."""
average_value = sum(values) / len(values) rounded_average = round(average_value, 2) return rounded_average
इंटरमीडिएट Python फॉर डेवलपर्स

Docstring एक्सेस करना

# हमारी docstring एक्सेस करें
print(average.__doc__)
मानों के अनुक्रम का औसत निकालें और दो दशमलव तक राउंड करें.
इंटरमीडिएट Python फॉर डेवलपर्स

Docstring अपडेट करना

# फंक्शन की docstring अपडेट करें
average.__doc__ = "Calculate the mean of values in a data structure, rounding the results to 2 digits."


print(help(average))
Help on function average in module __main__:

average(values)
    Calculate the mean of values in a data structure, rounding the results to 2 digits.
इंटरमीडिएट Python फॉर डेवलपर्स

मल्टीलाइन docstring

def average(values):
    """
    Find the mean in a sequence of values and round to two decimal places.






    """

average_value = sum(values) / len(values) rounded_average = round(average_value, 2) return rounded_average
इंटरमीडिएट Python फॉर डेवलपर्स

मल्टीलाइन docstring

def average(values):
    """
    Find the mean in a sequence of values and round to two decimal places.

    Args:




    """

average_value = sum(values) / len(values) rounded_average = round(average_value, 2) return rounded_average
इंटरमीडिएट Python फॉर डेवलपर्स

मल्टीलाइन docstring

def average(values):
    """
    Find the mean in a sequence of values and round to two decimal places.

    Args:
        values (list): A list of numeric values.



    """

average_value = sum(values) / len(values) rounded_average = round(average_value, 2) return rounded_average
इंटरमीडिएट Python फॉर डेवलपर्स

मल्टीलाइन docstring

def average(values):
    """
    Find the mean in a sequence of values and round to two decimal places.

    Args:
        values (list): A list of numeric values.

    Returns:
        rounded_average (float): The mean of values, rounded to two decimal places.
    """

average_value = sum(values) / len(values) rounded_average = round(average_value, 2) return rounded_average
इंटरमीडिएट Python फॉर डेवलपर्स

Docstring एक्सेस करना

# Help
print(help(average))
Help on function average in module __main__:

average(values)
    Find the mean in a sequence of values and round to two decimal places.

        Args:
            values (list): A list of numeric values.

        Returns:
            rounded_average (float): The mean of values, rounded to two decimal places.
इंटरमीडिएट Python फॉर डेवलपर्स

अഭ्यास करते हैं!

इंटरमीडिएट Python फॉर डेवलपर्स

Preparing Video For Download...