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.

Python Object-Oriented Python Instant Objects Your first method

How to call attribute of a class in a method inside that same class

I feel like this exercise is easy but i overthink something here.

class Student:
    name = "Your Name"
    def praise:
        print('Good job {}' .format(self.name))
sergio alvarez
sergio alvarez
15,205 Points

Hi Karol, Python is picky, A couple of things you were missing

  • you have to use parenthesis since this is a method ()
  • Inside the method you have to use the attribute self
  • You do not use print, you use return you cannot leave an extra space between the string and the format.

This should work

class Student: name = "Your Name" def praise(self): return ('Good job {}'.format(self.name))

1 Answer

Steven Parker
Steven Parker
221,328 Points

Sergio is mostly right, but the space doesn't actually cause any problem. It is a bit unconventional to put one there, though.

Also, in case that last suggestion wasn't clear:

  • the function needs to "return" the formatted string
  • you won't need to "print" anything