शुरू करेंमुफ़्त में शुरू करें

सिंगल-लाइन docstrings

Docstrings का उपयोग किसी फंक्शन के उद्देश्य को समझाने के लिए किया जाता है. फंक्शन का नाम वर्णनात्मक होना चाहिए, लेकिन नाम बहुत लंबा भी नहीं होना चाहिए, इसलिए docstrings आपको अधिक विवरण देने की सुविधा देती हैं.

इस अभ्यास में, आप पहले से बनाए गए calculate_discount() फंक्शन में एक सिंगल-लाइन docstring जोड़ेंगे.

यह अभ्यास पाठ्यक्रम का हिस्सा है

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

पाठ्यक्रम देखें

अभ्यास निर्देश

  • यह docstring जोड़ें: """Calculate the discounted price of a product.""".
  • उचित एट्रिब्यूट का उपयोग करके फंक्शन की docstring को एक्सेस करें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

def calculate_discount(price, discount_percent=15, round_result=True):
    # Add a single-line docstring
    ____
    
    discounted_price = price - (price * (discount_percent / 100))
    if round_result == True:
        return round(discounted_price, 2)
    else:
        return discounted_price

# Access the docstring
print(calculate_discount.____)
कोड संपादित करें और चलाएँ