1. Learn
  2. /
  3. Courses
  4. /
  5. Writing Functions in Python

Connected

Exercise

Retrieving docstrings

You and a group of friends are working on building an amazing new Python IDE (integrated development environment -- like PyCharm, Spyder, Eclipse, Visual Studio, etc.). The team wants to add a feature that displays a tooltip with a function's docstring whenever the user starts typing the function name. That way, the user doesn't have to go elsewhere to look up the documentation for the function they are trying to use. You've been asked to complete the build_tooltip() function that retrieves a docstring from an arbitrary function.

You will be reusing the count_letter() function that you developed in the last exercise to show that we can properly extract its docstring.

Instructions 1/3

undefined XP
  • 1

    Begin by getting the docstring for the function count_letter(). Use an attribute of the count_letter() function.

  • 2

    Now use a function from the inspect module to get a better-formatted version of count_letter()'s docstring.

  • 3

    Now create a build_tooltip() function that can extract the docstring from any function that we pass to it.