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

Class Instance call - Clarification

In this exercise, from my understanding, I am requested to create a class by the name of student. After having included the specified arguments and method. I move to call the function by created first; an instance of the class and subsequently passing the class and method name.

An instance of the class has been created, including within it the name variable.

I get the below error message:

Didn't find the name in the praise message. Be sure to use the instance attribute!

Assistance kindly requested.

first_class.py
class Student:
    name = "Emmanuel"

    def praise (self):
        name = Student.name
        return '{}, you are a GENIUS!'.format(name)

learner = Student.praise('')
print(learner)

2 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,722 Points

Nice work-- you are pretty close!

You need to refer to the name inside Student the student class as self.name The extra name assignment is not necessary, but it shows you are thinking ahead when the class will use a class constructor __init__(self,name) that you will see in a future lesson.

They are looking for somthing really simple in the challenge, so you don't need the extra code outside of the class definition.

class Student:
    name = "Emmanuel"
    def praise (self):
        return '{}, you are a GENIUS!'.format(self.name)

Thanks