Explains Class and Methods of OOP(Python)
So, first thing might be what is object oriented program ??
In real world everything around us are object like TV,Laptop,Pencil,Headphone. Similarly in OOP(Object Oriented Programming) image,audio,video or anything can be considered as object.
So, what's it's use in languages like python ?? If you have ever coded in C you first have to declare what type of variable you are using.
like In C : int i; i = 1;
In this above small program you have to declare what type of identifier you are using and If you see clearly you are getting restricted in this case suppose you have to store and image in the variable then how can you do it in C ?? (You can do it but it is a little complex)
But in Python it is easier to assign any value or any image or any video to any variable (In this variable acts like container which can store anything) without even declaring its type.
Like In Python: i = 1; i = ๐ช; or i = "๐ช";
But this is just the tip of OOP the main benefit of OOP is linked with its Class and Methods:
But what is Class and Method in python ??
First lets understand what is method in python . Let me give you an example : In Python: l1 = [] l1.append() l1.pop()
l1 is a list type and you can use append() and pop() functions with the variable itself. This append() and pop() are methods of list. Methods are nothing but functions defined inside class.
Then what is class??? Suppose you are a student of KV Thane and you have your ROll number but there are many other students like you so to make it easy we make a class of KV Thane students.
But you might say what is its profit you can even make a csv file or dictionary or list for it. But wait what i said about methods. In Class you can also define your own functions and use them with your variables and like append() of list you can use your own functions with the class.
SO, Methods are nothing but just functions which are defined in class and can only be accessed by that class.
I would suggest you to make a python program with class and methods and instances in it from scratch so you will be able to get the better understanding of it.
Also There might be mistakes in my explanation . I would encourage suggestions and corrections.!