Session Ready
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.

Note that in Python, you can pass a function as an argument to another function. I'll talk more about this in chapter 3, but it will be useful to keep in mind for this exercise.

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

      Use the inspect module again to get the docstring for any function being passed to the build_tooltip() function.