I can't think of any practical example for "is-a" in programming right now, but conceptually, take this:
A teacher is a human. This can be modelled by having a class inheritance:
class Human
class Teach(Human)
A teacher also might have a schoolbook. This is a "has-a" relation, as the teacher doesn't derive of schoolbook, but instead uses it:
class Human
class Schoolbook
class Teacher(Human)
def __init__(self)
self.book = Schoolbook()
This is achieved via aggregation, as I've shown here. Thats whats meant by "reference each other". The Teacher references a Schoolbook, in that it posses & possibly uses it.
def __init__(self, name):
self.name = name
why we must type this line ?? (self.name = name)
__init__ is a function, executed with a bunch of parameters. at that point "name" is merely a local variable, but you want to use it as a class variable. So in order to do that, you have to assign the local "name" variable to the instance of the class ("self"), by calling "self.name" (this instances "name" variable) "= name" (is assigned the local "name").