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

Sabine Lazuhina
Sabine Lazuhina
2,334 Points

I am stuck. What is wrong?

Why does it keep on asking to add 'Student'?

first_class.py
class Student(object):
    self.name = "Sabine"

    def praise(self, name):
        return("You're doing a great job,{}!".format(name))

1 Answer

Kyle Knapp
Kyle Knapp
21,526 Points

Since you aren't using the __init__ method, self.name isn't needed to set the name property. In fact, self.name is actually causing an error here because no instance of Student has been created yet, so there is no instance for self.name to refer back to. So, you'll just set the property using name = "name"

You also don't need to pass the name property as an argument to your praise method. Since the praise method is part of the Student class, it automatically has access to all of Student's properties, including name. You will however, need to use self to refer to the name property from the praise method, since a class's methods act on the properties of the class's instances.

Don't worry if none of this makes sense. I had to read the Python documentation for classes several times before I understood anything, and even now I still don't really get it. It takes time and a lot of repetition to develop an understanding of how classes and self work.

class Student(object):
    name = "Sabine"

    def praise(self):
        return(self.name)