I have been trying to understand class in python and failed to use it any useful purpose. Then, I came across this webage where I got a clear understanding of Class in Python. To understand this, I went through so many pages and blogposts. But I didn't get it.
https://micropyramid.com/blog/understand-self-and-__init__-method-in-python-class/
See the code blow (taken from above link).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | class Car(object): """ blueprint for car """ def __init__(self, model, color, company, speed_limit): self.color = color self.company = company self.speed_limit = speed_limit self.model = model def start(self): print("started") def stop(self): print("stopped") def accelarate(self): print("accelarating...") "accelarator functionality here" def change_gear(self, gear_type): print("gear changed") " gear related functionality here" |
This code is an example for a class in python language.
As you can see, this is a collection of functions (def) grouped in a class named Car.
What is the use of Class?
Class is used to collect list of definitions and provide a functionality to crosscommunicate with all other definitions inside the Class.
What is the best explanation for Class? Do you have any link?
Comment and provide link here.
Thanks.
No comments:
Post a Comment