Curriculum
In this lesson, you will learn about python docstrings in depth and how to use it in your python program with examples.
Docstrings or Python documentation strings are used after the definition of a function, method, class, or module. It provides an efficient method of associating documentation with Python modules, functions, classes, and methods.
Docstrings in python, use triple quotation marks for documentation. It is similar to commenting in python, docstrings are used to document a specific segment of code.
Docstrings in python use triple quotation marks for the documentation of all modules, functions, classes, and methods.
Single line docstrings are the documents that fit in one line.
Multi-line docstrings consist of a full detailed summary like document, where the first line is a one-line docstring, followed by a blank line, and by a more detailed description.
Look at the below example.
def docstring_function(): print('Developer Publish Academy') ("""About Developer publish academy""") ('''Developer publish academy teaches python programming. Python programming course in Developer publish academy is the best in the market. All the lessons are neatly drafted and are very much understandable. You can learn programming easily by self-learning the course''') docstring_function()
Here, the docstrings have started just after the function definition and it gives a detailed note. We have given a random description in this example, but you can provide an exact detailed note for the function. It helps the other users to identify the use of the function or the logic of the program.