मराठी

How will you create a constructor in Python?

Advertisements

प्रश्न

How will you create a constructor in Python?

टीपा लिहा
Advertisements

उत्तर

  • In Python, there is a special function called “init” which acts as a Constructor.
  • It must begin and end with a double underscore.
  • This function will act as an ordinary function; but the only difference is, it is executed automatically when the object is created.
  • This constructor function can be defined with or without arguments.
  • This method is used to initialize the class variables.

The general format of _init_method (Constructor function):
def _init_(self, [args………… ]):
< statements >

shaalaa.com
Constructor and Destructor in Python
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 10: Python Classes and objects - Evaluation [पृष्ठ १८७]
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×