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 trialAlice Giandjian
3,636 PointsObject-Oriented Python First Class
I'm not sure why this isn't working? What am I doing wrong?
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
7,647 PointsHi 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
7,647 PointsThomas Harris
7,647 PointsOh and you need to format with your string with
self.name
to reference the 'name' attribute in thepraise()
function ;)Alice Giandjian
3,636 PointsAlice Giandjian
3,636 Pointsthank you so much! that makes sense!