Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Hai Phan
2,442 PointsI don't know how to add an attribute to a method, can someone please help?
In challenge 1 in OOP, I try
class Student:
name = "Hai"
def praise(self):
self = name #This is where I don't know what to do
return print("Good job, {}".format(self))
Now I got stuck and I don't have any idea about things interact inside Class!
2 Answers

Steven Parker
216,083 PointsYou don't need to add a new attribute, what you need is already stored in the class as "self.name
".
And you only need to return the string directly, you do not need to "print" anything.

horus93
4,333 PointsYea Hai, you can even do
return "Good job {}".format(Student.name)
To get the same output I noticed fooling around in my IDE, but it won't pass the challenge unless you use self.name.

Steven Parker
216,083 PointsYou should always reference a non-static property using the instance name, not the class name.
Hai Phan
2,442 PointsHai Phan
2,442 PointsI did it but the name attribute didn't store
Steven Parker
216,083 PointsSteven Parker
216,083 PointsIt's already stored, you just need to reference it:
Hai Phan
2,442 PointsHai Phan
2,442 PointsThank you, Steve, now I got it.