Look at the Django source code, class inheritance do not understand, so learn to learn first.
1 #-*-coding:utf-8-*-2 3 classSchoolmember:4 def __init__(self,name,age):5Self.name =name6Self.age = Age7 Print 'init schoolmember:', Self.name, Self.age8 9 defTell (self):Ten Print 'name:%s; age:%s'%(Self.name, Self.age) One A - classTeacher (schoolmember): - def __init__(self,name,age,salary): the #inherit the Schoolmember class, name, Age property???? Is this a succession or a rewrite? - #first, the parent class is inherited, first initialized in the parent class, and then inherited . -Schoolmember.__init__(self,name,age) -Self.salary =Salary + Print 'init Teacher:', Self.name - + defTell (self): ASchoolmember.tell (self)#calling a method of the parent class at Print 'Salary:', Self.salary - - - classStudent (schoolmember): - def __init__(self,name,age,marks): - #and inherit that . inSchoolmember.__init__(self,name,age) -Self.marks =Marks to Print 'init Student:', Self.name + - defTell (self): the Schoolmember.tell (self) * Print 'Marks:', Self.marks $ Panax Notoginseng - if __name__=="__main__": thet = Teacher ('Yanggang', 20, 1000) +s = Student ('liming', 12, 86) A #Members = [T,s] the #Print + #For member in Members : - #Member.tell ()
(1) After inheriting the parent class, using the instance of the subclass, the parent class will go first,
Schoolmember. __init__
Summarize
Classes for Python