Computer Science, asked by lalitsaraswat8842, 1 year ago

Program for implementation of constructor in python

Answers

Answered by 3rdranjan
0

i don't know answer ,but please answer my question, which option I use to get a object code of a software written in python in python shell

Answered by tiger009
0

Constructor in python

Explanation:

A constructor is the unique type of method of the class that call at the time of the creation of object of the class and which is used initialize the object of the class, every time when we create an object of the class there is always default constructor is called automatically.

Note: Indentation is important in Python.

Syntax:

def __init__(self):

  '''body for execution of the code

     or print any statement'''

Example:

#define class

class test:

 #define constructor

 def __init__(self):

   #print message with result

   print('sum: ',2+3)

#create object and call constructor

ob =test()

Output:

sum:  5

  • Define class 'test' and inside the class.
  • Define constructor and inside it print message and result.
  • Finally, create object of the class and constructor automatically called.

Learn More:

brainly.in/question/14867626

Similar questions