python / beginner
Snippet
Documenting Code with Docstrings
Docstrings are literal strings used right after a function definition to explain what the function does. They use triple quotes.
snippet.py
1
2
3
def calculate_area(radius):"""Calculates the area of a circle."""return 3.14 * radius * radius
Breakdown
1
"""Calculates the area of a circle."""
A documentation string that describes the function's purpose.
2
return 3.14 * radius * radius
The math logic that sends the result back to the caller.