Python Start To Learn Python Right Now EP17: Python Classes

In this post, we are going to learn about Class objects in Python. We are using a class to operate a few functions and store a massive number of commands inside one operation. It is very useful when creating programs that work with a few Python script files. It also works as a constructor for objects. Now let's see how to create a Class


Creating Classes 


In the above code, I made a class and I put a function. inside it. Then I made a variable with the class function. And I call the operations inside the function.  


Work With Class __init__ functions

  In the above code, we call the function in the class using a function name. But __init__ functions are a bit different from normal functions. You no need to call __init__ functions with the class name or without it. 


In the above code, I didn't call the function. I just put the parameters and arguments for the function. And it begins to get the operations. This is how to run a __init__ function. 

    Also, we can take classes with a few functions. This is a function I made a bit advanced but simple with the knowledge we learned today. 



   In the above code, we use two functions. But you have to call the function using the class name. but we can get the data of __init__ to the second function using the self.  Now let's see what is self.

What is Self

 self is a parameter like a label. It is used to create variables that belong to this class. It means we can use any variable defined with self in other functions inside the same class. It's very useful to transfer the same data through different functions and operations. 

This is all I need to explain about Python Classes. If you have any questions feel free to comment below.  

Post a Comment

If you have any doubt, Let us know

Previous Post Next Post