First, what is the new class classic class?
# the new class refers to the class that inherits the object class A (obect): ... .. # Classic class refers to a class that does not inherit object class A: ......
Python recommends that you use the modern Class 1. New sure good ha, already compatible with the classic class
2. Fixed multiple inheritance bug in classic class
Let's focus on the multiple inheritance bug
BC is a subclass, D is a subclass of BC, there is a Save method in a, and C overrides it.
In the classic class, call D's Save method to search for the depth-first path, B-A-C, to execute the save in a is obviously unreasonable
The Save method in the call d of the new class is searched by the breadth-first path b-c-a, executed as C in save
(for depth first, breadth first puzzled dot here)
#Classic ClassclassA:def __init__(self):Print 'This is A' defSave (self):Print 'come from A'classB (A):def __init__(self):Print 'This is B'classC (A):def __init__(self):Print 'This is C' defSave (self):Print 'come from C'classD (b,c):def __init__(self):Print 'This is D'D1=D () d1.save ()#The result is ' come from A '
#New ClassclassA (object):def __init__(self):Print 'This is A' defSave (self):Print 'come from A'classB (A):def __init__(self):Print 'This is B'classC (A):def __init__(self):Print 'This is C' defSave (self):Print 'come from C'classD (b,c):def __init__(self):Print 'This is D'D1=D () d1.save ()#The result is ' come from C '
The difference between the new class classic class in Python (that is, whether the class inherits object)