Try
def add_greeting(L=[]):
""" (list) -> NoneType
Append 'hello' to L and print L.
>>> greetings_list = ['hi', 'bonjour']
>>> add_greeting(greetings_list)
['hi', 'bonjour', 'hello']
>>> greetings_list
['hi', 'bonjour', 'hello']
"""
L.append('hello')
print(L)
if __name__ == '__main__':
import doctest
print(doctest.testmod())
You get the error because you have print(L)
at the end of add_greeting
but your sample console output in the docstring does not expect anything to be printed or returned by add_greeting
.