I'm having trouble understanding the example that was given. up until now, the method we defined inside the class took only one argument - "self". now it takes another one called "other". why does "other" have a "name" attribute? where did we define it? thanks in advance...

class Employee(object):
    def __init__(self, name):
        self.name = name
    def greet(self, other):
        print "Hello, %s" % other.name


Remember, a function in a class can have any number of arguments but it must have a self argument.


other will be a class instance, in this specific case ceo:


ceo has a name attribute

the argument ceo now is stored in other (remember arguments and parameters?)


ok, so If I understand correctly, if we didn't define an "other" inside the brackets, calling out:

emp.greet(ceo) will give an error? because it will only work in emp.greet()?


great, thanks. I was thrown off by the exercise example as well.
I thought all the variable definitions are all made inside the init function or as member variables, but then hours was defined inside calculate_wage... I think I have it figured out now (the "Classes" Lesson made it a bit more clear ).


yes, the amount of parameters must equal the numbers of arguments at function call


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.