Constructor (object-oriented Programming) - Python

Python

In Python, constructors are created by defining an __new__ method, and are called when a new instance is created by calling the class. Unlike other languages such as C++, derived classes in Python do not call their base classes' constructors. However, when a constructor is not defined, the next one found in the class's Method Resolution Order will be called. Due to Python's use of duck typing, class members are often defined in the constructor, rather than in the class definition itself.

In case of the initial values (not methods) are needed, the __init__ method can be defined.

class ExampleClass(object): def __new__(self): # We override the constructor to return none instead. return None exampleInstance = ExampleClass print exampleInstance None

Read more about this topic:  Constructor (object-oriented Programming)