Product SiteDocumentation Site

9.5. Docstrings

In Python we use docstrings to explain how to use the code, it will be useful in interactive mode and to create auto-documentation. Below we see an example of the docstring for a function called longest_side.

text
#!/usr/bin/env python
import math

def longest_side(a, b):
	"""
	Function to find the length of the longest side of a right triangle.

	:arg a: Side a of the triangle
	:arg b: Side b of the triangle

	:return: Length of the longest side c as float
	"""
	return math.sqrt(a*a + b*b)

if __name__ == '__main__':
	print longest_side(4, 5)

We will learn more on docstrings in reStructuredText chapter.