Note whether the current Python version is 2.X or 3.x,python 3.X has a greater change in the use of super than Python 2.X; 1. Python 2.x
Class Contact (object):
all_contacts = []
def __init__ (self, Name, email):
self.name = name
Self.email = Email
Contact.all_contacts.append (self)
class Friend:
def __init__ (self, name, email, phone):
Super (Friend, self). __init__ (name, email)
Self.phone = Phone
In the Python 2.x environment, for a parent class that needs to be inherited, you need to explicitly inherit the parent class from the object class, otherwise use super (subclass, Self) in the subclass. __INIT__ () will be reported Typeerror:must is type, not classobj.
This is because of the Python 2.x:
>> Class A ():
pass
>> type (a)
classobj
>> Class A (object):
Pass >> type (A)
type
and Python 2.x does not treat classobj as type.
Of course, it is also possible to use such a statement in a subclass:
Class Friend:
def __init__ (self, name, email, phone):
contact.__init__ (self, name, email, phone)
Self.phone = Phone
Python super () usage encounters typeerror:must be type, not classobj 2. Python 3.x
Class Contact:
all_contacts = []
def __init__ (self, Name, email):
self.name = name
Self.email = Email
contact.all_contacts.append (self)
class Friend (Contact):
def __init__ (self, name, email, phone):
Super (). __init__ (name, email)
Self.phone = Phone