Python class init method is a reserved method in python classes. It represents a constructor in Python. When an object creates it is called and it allows the class to initialize the attributes of a class.
As you know if you know another object-oriented programming constructors are used to initialize the object’s state. It is initialized (assigns values) to the data members of the class when an object of the class is created.
Example __init__ in Python
Simple example code class with the init method in Python.
class Person: # init method or constructor def __init__(self, name): self.name = name # Sample Method def greeting(self): print('Hello,', self.name) p = Person('John') p.greeting()
Do comment if you have any doubts and suggestions on this Python basic tutorial.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.