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 Object-Oriented Python Instant Objects Your first method

Ingrid Matthews
Ingrid Matthews
1,465 Points

using "self"

I have tried about a million permutations of this. I would appreciate help with what's wrong with my code!

first_class.py
    class Student:
    name = "Ingrid"

    def praise(self):
        praise_message = ("Great job, {}!".format(name))
        return(praise_message)

    return self.praise

1 Answer

Steven Parker
Steven Parker
229,785 Points

You're close, but I see three issues:

  • the "class" line should not be indented
  • the reference to "name" in the "praise" method needs a "self." prefix
  • the last line with "return" on it is not part of the method and is not needed
Ingrid Matthews
Ingrid Matthews
1,465 Points

Thank you so much Steven, but I may have misunderstood you. Tried this (below), and failed again:

class Student: name = "Ingrid"

def praise(self):
    praise_message = ("Great job, {}!".format(self.name))

return self.praise
Steven Parker
Steven Parker
229,785 Points

The first "return" was an important part of the method and should stay, the last one is the one to remove.