Python Forum

Full Version: Constructor
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,
Just wanted to know in what scenario we need to override the constructor in python?
And how to do that?

Thanks
Please elaborate
Python doesn't have by-name overloading like you might see in C++ or Java. It does have named and optional parameters, which can be used to get "overloaded" behavior. You do this by (for example) providing a default value of None, then checking the value inside the single "constructor" (which is usually called an initializer in this case, the __init__ method).