top of page
Search
techskill065

Default , Parameterized and Non -parameterized Constructor





Constructor in Python


Python Constructor is a sort of procedure used to activate instance members of a class in Python object-oriented programming.




Python Constructor Rules


It, like all other Python functions, initiates with the def keyword.


It is followed by the word init, which would be prefixed and suffixed with a series of brackets, i.e., __init__ ().


It takes a self argument and seems to be using it to designate values to the variables.


Self is a reference to the class's current instance. When the function Constructor is called, it is generated and automatically/implicitly carried to the __init__() function.


Constructor types include:




Default Constructor:


The default Constructor is a simple function Constructor which doesn’t recognize any arguments.


Parameterized Constructor:


A parameterized Constructor is a function Constructor that receives metrics. The parameterized Constructor carries a reference to the instance being constructed established as self as its first argument, and the rest of the arguments are presented by the programmer.


Non-parameterized Constructor


A non-parameterized Constructor can be utilized when we want constructor to get something but none of it requires influencing values.


Summary


So here, we learned about the constructors rules , types of constructor default , parameterized constructor and non-parameterized constructor .

Learn more about constructor overloading in python in our blog here .


2 views0 comments

Comments


Post: Blog2_Post
bottom of page