Python Docstrings
Python Docstrings
- Python documentation strings (or docstrings) provide a convenient way of associating documentation with Python modules, functions, classes, and methods.
- It’s specified in source code that is used, like a comment, to document a specific segment of code. Unlike conventional source code comments, the docstring should describe what the function does, not how.
How docstring look like?
- The doc string line should begin with a capital letter and end with a period.
- The first line should be a short description.
- If there are more lines in the documentation string, the second line should be blank, visually separating the summary from the rest of the description.
- The following lines should be one or more paragraphs describing the object’s calling conventions, its side effects, etc.
- Doc String can be one liner or multiliner based on requirements with proper indentation.
Accessing Docstrings: The docstrings can be accessed using the __doc__ method of the object or using the help function.
Example:
class Student:
'''This class is about Student details by VDS TECH LABS'''
def studentDetails(self):
'''This fun is about Student data'''
self.name='VDS TECH LABS'//Accessing the doc string:
print(Student.__doc__)
print(Student.studentDetails.__doc__)
Comments
Post a Comment