in Python by
How can we create a constructor in Python programming?

1 Answer

0 votes

The _init_ method in Python stimulates the constructor of the class. Creating a constructor in Python can be explained clearly in the below example.

class Student:  

def __init__(self,name,id): = id; = name;  

def display (self):  

print("ID: %d nName: %s"%(,  

stu1 =Student("nirvi",105)  

stu2 = Student("tanvi",106)  

#accessing display() method to print employee 1 information     


#accessing display() method to print employee 2 information  



ID: 1

Name: nirvi

ID: 106

Name: Tanvi

Click here to read more about Python
Click here to read more about Insurance

Related questions

0 votes
asked Feb 11, 2020 in Python by rahuljain1
0 votes
asked May 17, 2020 in Python by SakshiSharma
0 votes
asked Dec 19, 2019 in Python by sharadyadav1986
0 votes
asked May 16, 2020 in Python by Robindeniel
0 votes
asked Mar 8, 2020 in Git Slack Integration by Hodge