Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Write Better Python Cleaner Code Docstrings

Why doesn't my string get approved by "Check Work"?

Whenever I type the second string into either the function, class or both, I always get an error? The preview never is available. What am I doing wrong?

Could you provide us with your code?

1 Answer

Jeff Muday
Jeff Muday
Treehouse Moderator 27,653 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)