Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Question: How can we create a constructor in Python programming?
Answer:

The _init_ method in Python stimulates the constructor of the class. 

Example:

class Person:
  def __init__(self, name, age):
    self.name = name
    self.age = age

p1 = Person("John", 36)

print(p1.name)
print(p1.age)

Output:

John

16

Is it helpful? Yes No

Most helpful rated by users:

©2025 WithoutBook