21 Implementation of Init and Self Method in Class of Python Programming.

Опубликовано: 19 Февраль 2026
на канале: Free Tutorial TV
3
1

And we have used this special keyword pass there .
and pass we were using to create an empty class.

Now I'm going to remove this pass .
and I'm going to add a method call init.

So I'm going to just write def and then underscore underscore init and then press enter and you

can see this init method is created here.

So this is like a normal method with double underscore in front and back of this is init keyword.
and

you will also see these self keyword is already added as the first argument of this method.

Now this init method serves as a constructor for the class.

So usually it is used to initialize some attributes or some functions.
because this is the first method

which will be called when you create an instance of a class.

So here we are creating an instance of a class and this init method will be the first method which

will be called when this object or instance will be created.

So let's check what I'm saying.

So let's say I want to print inside this init method that the underscore underscore init and underscore

underscore is called.

And let me run this course I will change this to car and then run this code.

And now when I see this result you will see this line is called three times because we have created

three instance from the same class.

OK.

So every time in this instance is created this print is called and that's why this line is printed three

times and everything as will be printed.

After that whatever you are printing for example speed or color of the car will be printed after that.

Now one important thing to notice here is I said init serves as a constructor.

**************************************************************************
please like and follow us in Facebook and Instagram.
facebook:   / technologytv  


Instagram:   / heikhamsingh  


Twitter:   / hanandkumarsing