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 dont understand what half of these words mean.

I don't feel that the Kenneth explained this superbly, and honselty I have absolutely no idea what to do. I don't even know what words like: method, instance, self, and attribute are.....

first_class.py
class Student:
    praise = Student(self)


    name = "Your Name"

1 Answer

boi
boi
14,242 Points

Let's start by solving each problem.

method ----> A function which is written in a class

instance or self (same thing) ----> An object which belongs to a class

attribute ----> A variable which is written in a class

Explanation in real-time, using the challenge code 👇

class Student:   👈 #The challenge first tells you to create a class named Student

    name = "Your Name"  👈 #The variable "name" is called an attribute because it is a variable inside of a class

    def praise(self): 👈 #The challenge then tells you to create a method named praise
                                    # Note :- A function is called a method inside a class
                                    # Just remember that whenever you create a method ( or function inside of a class) it will take a 
                                    #  first parameter "self" by default


        return("You're doing great, {}".format(self.name))

         #The challenge then wants you to return a positive message using the attribute "name"
            # Notice in the return, there is this "self" prepended to "name".
            # The word "self" refers to an instance of a class, An instance is an object which is assigned to a class for example

>>> this_is_an_instance_of_class_Student = Student()

# The "self"  equals to "this_is_an_instance_of_class_Student"
#So to access any methods or attributes we prepend "self" and in the case of the above praise method, we used 
# "self.name"

Thanks so much boi, u really have cleared up a few things for me and this has really helped. Not gonna lie i was gettint a little bit disheartened by not knowing how to do these challenges. :)