0

There are two ways to document a module, function, or class in the code itself: comments and docstrings.

Docstrings are more functional, as they can be accessed via the help() function, while comments can only be accessed in the source code.

When should comments be used in place of docstrings?

2
  • 2
    Comments aren't documentation. Comments are for people reading the code. Documentation is for people using it. Commented Apr 21, 2019 at 6:04
  • I think the question is unclear. I mean docstrings that exist inside the source code, defined '''xxxx''' Commented Apr 21, 2019 at 6:05

1 Answer 1

1

Docstrings are meant to explain what a function does, in terms of what kinds and types of values it takes and returns, from a user's perspective.

Comments, on the other hand, being in the body of the source code, will only be visible to those actually reading it, and accordingly serve to explain how it does what it does.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.