background image

Doctest

def average(lst):

 

   """Return the average of a list of numbers.

    >>> average([2, 4, 0, 4])
    2.5
    >>> average([5])
    5.0
    """

    return sum(lst)/len(lst)

Include runnable code inside Python DocStrings.

Provides 

example

 of how to use the code 

and 

executable tests

!

doctest 
comments

Comments:

Unit Testing in Python

navigate_before navigate_next