I met this question as I learned Python on Codecademy, code as below:
class Employee(object):
def __init__(self, name):
self.name = name
def greet(self, other):
print "Hello, %s" % other.name
class CEO(Employee):
def greet(self, other):
print "Get back to work, %s!" % other.name
ceo = CEO("Emily")
emp = Employee("Steve")
emp.greet(ceo)
ceo.greet(emp)
I was wondering what does other.name mean here?
The self.name = name could be interpreted as a instance object's member variable self.name be set equal to name, so we can say that self is a instance and name is its property, right?
And, isn't the "Emily" assigned to the parameter other by ceo = CEO("Emily") and the "Steve" assigned to the name by emp = Employee("Steve")? How could it be used like that?
.nameproperty of theotherobject". other, which you passed emp to, is the employee object with the.nameproperty "steve"ceo.greet(emp)resolves toCEO.greet(ceo, emp)-ceoisself,empisother.