Python Tutorial
Python - Introduction Python - Syntax Python - Variable Python - Number Python - Casting Python - String Python - Operators Python - Conditions Python - Loops Python - List Python - Tuple Python - Set Python - Dictionary Python - Function Python - Module Python - Date & Time Python - Input Output Python - Error & Exception Python - File Handling
Python OOP
OOP - Introduction OOP - Class Members OOP - Constructor Destructor OOP - Data Hiding OOP - Inheritance OOP - Overriding OOP - Overloading

Python Overriding

In the previous chapter, we talked about superclasses and subclasses.

If a class inherits a method from its superclass, then there is a chance to override the method provided.

You can always override your parent class methods.

One reason for overriding parent's methods is that you may want special or different functionality in your subclass.

The following table lists some generic functionality that you can override in your own classes:

Method Description
__init__ ( self [,args...] ) Constructor (with any optional arguments)
__del__( self ) Destructor, deletes an object
__repr__( self ) Evaluatable string representation
__str__( self ) Printable string representation
__cmp__ ( self, x ) Object comparison

Python Abstract Class

Abstraction is a process of hiding the implementation details from the user, only the functionality will be provided to the user.

In other words, the user will have the information on what the object does instead of how it does it.

A class which contains at least one abstract method is known as abstract class.

If a class is declared abstract, it cannot be instantiated.

To use an abstract class, you have to inherit it from another class, provide implementations to the abstract methods in it.

If you inherit an abstract class, you have to provide implementations to all the abstract methods in it.