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

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.

first_class.py
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
229,732 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