docstring
A string literal placed as the first statement of a module, function or class, which Python keeps as its documentation.
In more detail
Docstrings are usually triple-quoted so they can span lines. help() and tools such as IDEs show them, which makes them the note the code itself cannot give: what a function is for, its arguments and what it returns. A comment is ignored; a docstring is kept.
Examples
def area(r):
"""Return the area of a circle of radius r."""def total(lines):
"""Total of (price in pence, count) lines."""Related terms
- comment — Text in a program after a # sign, which Python ignores and which exists only for human readers.
- triple-quoted string — A string literal written between three quote marks, ''' or """, which can span several lines.
- help() — A built-in function that shows the documentation, including the docstring, for a function, method, class or module.
- Python — A popular general-purpose programming language known for readable code and a large standard library.
- automated test — A small program that runs part of your code and checks that it did what you claimed it would.
Taught in
- First Run, And Fixing A Broken Install — Hands-on Python: Complete Video Course & Book
- A Sample Program, Explained — Hands-on Python: Complete Video Course & Book
- The Idle Editor And Running Programs — Hands-on Python: Complete Video Course & Book
- Methods, Attributes And self — Hands-on Python: Complete Video Course & Book
- Formatting, Linting And Style — Hands-on Python: Complete Video Course & Book
- The Cost And Value Of A Test — Automated Testing, TDD & Quality Engineering
- Introducing pytest — Automated Testing, TDD & Quality Engineering