Version: 1.1.0
Docstrings
A docstring is a string literal placed as the first statement of a function, struct, or trait. mojo doc collects them.
Essentials
- Triple double quotes are the usual form.
- The first sentence is the summary.
- Later sections name Parameters, Args, Returns, and Raises.
- Docstrings are data, not comments, so they exist in the program.
- Keep the summary shorter than one line.
Example
fn area(w: Int, h: Int) -> Int:
"""Return the area of a rectangle.
Args:
w: Width.
h: Height.
"""
return w * h
Keep in mind
Write the docstring for a caller who has not opened the file.