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

I cannot see what is wrong with my code

It appears I have used the correct syntax - any ideas?

first_class.py
class Student:
    name = "Your Name"


    def praise(self):
        print("Great work, {}!".format(self))
        return

What are the errors that you are seeing. Running this on my machine seems to work just fine

Thanks for your response. Turns out there is nothing wrong with the code but I had been asked to return a string and not print. Thank you

1 Answer

Cameron Childres
Cameron Childres
11,817 Points

Hi A Fletcher,

Two things to note:

  • The task wants a string returned, not printed
  • The string needs to include the name attribute

You did a good job creating the method with the self argument. To access the name attribute you'll use self.name

All together it will look like this:

class Student:
    name = "Your Name"

    def praise(self):
        return "Great work, {}!".format(self.name)

Hope this helps! Let me know if you have any questions.

Spot on - thank you!