Monday, May 15, 2017

Constructors (Initializers) in Python

When you define a class in Python you can include constructor functions (actually initializers in Python) to initialize the instance variables. You can define them to accept arguments when the class is instantiated or to accept no arguments. This accomplishes more or less the same thing as overloaded constructors in Java. In this latter case in Python you would initialize the parameter variables to a desired default value in the constructor declaration. You would not write a separate constructor. Here is the code...

 Expanded image of constructors
Click for enlarged view

No comments:

Post a Comment