Q. What are doc-strings? What is their significance? Give example to support your answer.


Answer =

A doc-string is just a regular Python triple-quoted string that is the first thing in a function body/ a module/ a class. When executing a function body (or a module/ class), the doc-string doesn't do anything like comments, but Python stores it as part of the function documentation. This documentation can later be displayed using the help() function.

So, even though doc-strings appear like comments (no execution), they are different from comments

For example:-

def add(x, y):
'''this function add two numbers'''
     return x + y

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post