import doctest doctest. testmod () It's same code like docstring example but I add example and doctest at last line of the code. In order to test the docstring just run the file python my_math.py. If ...
Pythonには、docstringの内容に応じたテストを行う doctestモジュールが標準で含まれている。 docstringの中に入出力例を書くだけなので簡単、かつ、 ドキュメントとしても分かりやすくなる。