User Guide

147
BusinessContactEntry then you can override the inherited
versions.
class BusinessContactEntry(AddressBookEntry):
company = ""
def __init__(self, firstname, lastname, company):
self.firstname = firstname
self.lastname = lastname
self.company = company
def printName(self):
print(self.firstname+" "+self.lastname+" (" +
self.company + ")")
Where this gets interesting, is if you have a function like the
example below:
def printEntry(entry):
entry.printName()
This function accepts either type of object, and does not know
the difference. It simply calls the method printName() and the
two different types of object respond slightly differently.
Hiding Fields and Methods
In Python, you can stop other parts of your code accessing fields
and methods in an object by defining them with a name that
starts with two underscore characters.
class HiddenData:
__vat = ""
def __setVat(self, value):
self.__vat = value
The field __vat and the method __setVat can only be accessed
by code in the HiddenData object. You cannot access them from
other parts of your program.