Data Science · मराठी आवृत्ती · Python basics
P7.6 Python Function साठी Docstring कसं लिहायचं?
हे का शिकायचं?
सहा महिन्यांनी तुम्हालाच आठवणार नाही function काय करतं. Docstring ते सांगतो.
हे काय आहे?
def खालच्या पहिल्या line मधला """…""" text म्हणजे docstring. help() ने तो वाचता येतो.
कसं करायचं?
Step 1. def खाली """ लिहा.
Step 2. काय करतं, काय घेतं, काय देतं ते लिहा.
उदाहरणं: copy करा आणि चालवा
उदाहरण A: Document केलेलं cleaner function
हा code चालवा:
def clean_name(text):
"""Return a patient name with no outer spaces and Title Case."""
return text.strip().title()
print(clean_name(" maria lopez "))
print(clean_name.__doc__)
तुम्हाला दिसणारा output:
Maria Lopez
Return a patient name with no outer spaces and Title Case.
याचा अर्थ: help() ने docstring दिसला.