what is init in python

Solutions on MaxInterview for what is init in python by the best coders in the world

showing results for - "what is init in python"
Marlene
10 Apr 2020
1class Person:
2  def __init__(self, name, age):
3    self.name = name
4    self.age = age
5
6p1 = Person("John", 36) // Object definition
7
8print(p1.name)
9print(p1.age)
Colette
01 Jan 2021
1# If you are familiar with C++ or Java think of the __init__ method as a constructor.
2# It is the method that is being called when the class is called.In the following
3# example we will see how we can call the __init__ method
4
5my_variable = MyClass()