Python Write Better Python Cleaner Code Docstrings

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 26,165 Points

You won't be able to see anything in the preview related to the docstrings. It is unfortunate that having the "Preview" option is there since it doesn't do much for this particular challenge.

Below is a solution to challenge 1 of 2 as an example of what the Challenge grader is looking for. You should have no trouble figuring out part 2 on your own. Note that both a class and its methods can have docstrings. These docstrings are immediately below the declaration line and can use three single-quotes or double-quotes for delimitation. They can be on multiple lines to support extended or complex strings.

DocStrings are an easy way to document code and many IDE (integrated development environments) and Documentation generation tools can use the Docstrings in ways to inform users of the intent of a class or method and valid parameters that are passed. Some documentation generators produce beautiful PDF and HTML documentation using DocStrings so it is really worthwhile investing the time to type these in if you think your code is destined for lots of reuse!

class Treehouse:
    def student(self, name):
        """Gives a pleasant message about the student."""
        return '{} is a great Treehouse student!'.format(name)