Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Write Better Python Cleaner Code Docstrings

Rabih Atallah
Rabih Atallah
3,405 Points

identation error

Please why I get the error message: indentation error def student

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

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

The indention of an individual block of code must be consistant. The indention is set by the first line of the block. In your code, the first block statement is the doc-string comment (6 spaces). The function student() is indented only 4 spaces. So either remove two space in front of the doc-string (preferred), or add two spaces in front of the student() function.

class Treehouse:
    """Methods related to Treehouse and student.  #<-- two leading spaces removed
    """   #<-- two leading spaces removed
    def student(self, name):
        """Gives a pleasant message about the student."""
        return '{} is a great Treehouse student!'.format(name)

Edit: fixed student() docstring indention

Rabih Atallah
Rabih Atallah
3,405 Points

Thank you for your help Chris! I did it the way you suggested it's still not working which is really strange!

Chris Freeman
Chris Freeman
Treehouse Moderator 68,454 Points

Right, I missed another indention error. I updated my answer above to fix the docstring indention for student(). The docstring needs to be indented the same as the return statement.

Rabih Atallah
Rabih Atallah
3,405 Points

Thank you Chris it worked!