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

Object-Oriented Python First Class

I'm not sure why this isn't working? What am I doing wrong?

first_class.py
class Student:
    name = "Alice"

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

me = Student() 
praise(me)

1 Answer

Thomas Harris
Thomas Harris
7,647 Points

Hi Alice!

When you instantiate the class with me = Student() you then use the 'me' instance (variable) to call the functions in the class. Also, this snippet does not print anything; you could do that a couple of different ways, but this should do the trick:

class Student:
    name = "Alice"

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

me = Student() 
print(me.praise())
Thomas Harris
Thomas Harris
7,647 Points

Oh and you need to format with your string with self.name to reference the 'name' attribute in the praise() function ;)

thank you so much! that makes sense!