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

Back and forth between NameError and not having name defined

I have watched the video several times and don't know what I am doing wrong. I have included self in the method and thought I am structuring it correctly, but cannot get it to return the function properly. I have tried swapping in name into the string after the format method but keep getting stuck. What am I doing wrong?

first_class.py
class Student:
    name = "George"

    def praise(self):
        return "Go {}!".format(self)

1 Answer

boi
boi
14,242 Points

Let us analyze the code:

class Student:
    name = "George"

    def praise(self):
        return "Go {}!".format(self)

Hmmm, why did you format self here? self is nothing by an instance of the class Student, however self can be used on an attribute of a class like name attribute. try self.name

Thank you! That worked, and our explanation helped me understand what I was missing.