Docstrings लिखना
आपने अभी docstrings के फ़ायदों के बारे में सीखा. इस अभ्यास में, आप ऐसे docstrings लिखने का अभ्यास करेंगे जिन्हें Sphinx जैसे documentation जनरेटर द्वारा उपयोग किया जा सके.
ध्यान दें कि आपका docstring सबमिशन समाधान से बिल्कुल समान होना चाहिए. अगर आप कई बार ग़लत कर रहे हैं, तो नमूना कोड को ताज़ा करना और दोबारा शुरू करना बेहतर रहेगा.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Software Engineering Principles
अभ्यास निर्देश
- docstring के वे हिस्से पूरा करें जो पैरामीटर्स को डॉक्यूमेंट करते हैं.
- docstring में return value का वर्णन करने वाला हिस्सा पूरा करें.
- docstring में दिए गए example function usage को पूरा करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Complete the function's docstring
def tokenize(text, regex=r'[a-zA-z]+'):
"""Split text into tokens using a regular expression
:____ text: text to be tokenized
:param ____: regular expression used to match tokens using re.findall
:____: a list of resulting tokens
>>> ____('the rain in spain')
____
"""
return re.findall(regex, text, flags=re.IGNORECASE)
# Print the docstring
help(tokenize)