class define in python:
class AddressBookEntry(object):
version = 0.1
def __init__(self, name, phone):
self.name = name
self.phone = phone
def update_phone(self, phone):
self.phone = phone
subclass of the class:
class EmployeeAddressBookEntry(AddressBookEntry):
def __init__(self, name, phone, id, social):
AddressBookEntry.__init__(self, name, phone)
self.empid = id
self.ssn = social
def __init__(self, name, phone, id, social):
AddressBookEntry.__init__(self, name, phone)
self.empid = id
self.ssn = social
The object in the brackets is the class which we inherit from.
dynamic instance attributes, those that are not declared anywhere in the class definition, yet can be created “on the fly.”
We can use this like this:
We can use this like this:
Bob = AddressBookEntry('Bob', '2b7474748')
Bob.JJ = None
This inner class is a real Python class, but is only visible to instances of the MyClass class.
class MyClass(object):
class InnerClass:
pass
class InnerClass:
pass