Question

what is a docstring and what is its purpose? Where in the program are the docstrings...

what is a docstring and what is its purpose? Where in the program are the docstrings supposed to be placed? Why? What happens if you place them

elsewhere?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The answer to the question is given below.

What is docstring

A docstring is a string literal that comes at the first statement in a class, module or function definition.
It becomes a special attribute of the object.
__doc__

Purpose of docstring
Python documentation string as the docstring. They provide a convenient way of documentation of python functions, classes, methods, and modules.
It is simply a multi-line string, it is not assigned to any variable or anything else
It is just specified in the source code that is useful in documentation of specific code segments.

In the program, docstring are supposed to be placed at the starting of module, classes, function or method.
It is placed between triple quotes.
for example
"""This is a docstring."""
It starts with a capital letter and ends with a full stop(.)

Docstrings are placed at the start of module, function or classes. because it is convenient to understand anything after understanding the documentation.

We can't put the docstring everywhere in the program.
If a string is put at the start of classes, module or function. It is considered at docstring.
If we put docstring at anywhere then it is considered as a normal string object.







If the answer helped please upvote it means a lot. For any query please comment.






Add a comment
Know the answer?
Add Answer to:
what is a docstring and what is its purpose? Where in the program are the docstrings...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT