You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-15
Original file line number
Diff line number
Diff line change
@@ -69,7 +69,7 @@ A python class is like a **blueprint to create a new object**. The objects havin
69
69
---
70
70
71
71
## Reason for creating a class:
72
-
To accumulate the data of similar properties and methods together.
72
+
To accumulate the data and functionalities of similar objects at one place.
73
73
74
74
By creating a new object we add this new instance, or any future instance, to a particular bundle. That bundle is called a `class`. If we have the same set of objects with similar attributes and functionalities we should create a class. Also, class supports inheritance. With classes we can reuse our codes or the codes written by other programmers. (Packages, modules and frameworks)
75
75
@@ -104,25 +104,33 @@ Let's say, we need to create a record of cars manufactured by the Tata Motors. T
104
104
MAKE = "TATA Motors"
105
105
Year = 2022
106
106
107
-
|Model|Color|Speed|
107
+
|Model|Category|Speed|
108
108
|-----|---|---|
109
-
|Altroz|Blue|160|
110
-
|Nexon|Grey|160|
111
-
|Harrier|Dark Grey|180|
112
-
|Safari|Black|170|
109
+
|Altroz|Hatchback|160|
110
+
|Nexon|Compack SUV|160|
111
+
|Harrier|SUV|180|
112
+
|Safari|MUV|170|
113
113
114
114
**A table containing details of each Car. The row of this table represents the each instance of a class and columns represents attributes associated with an instance of the Car class**.
115
115
116
116
For this we will create the Car class in Python like below:
117
117
118
118
```python
119
119
classCar:
120
+
"""A car class for all the models of a car company."""
120
121
MAKE="TATA Motors"
121
122
year =2022
122
123
123
-
def__init__(self, model, color, speed):
124
+
def__init__(self, model, category, speed):
125
+
"""Constructor of Car class with model, category and speed.
@@ -177,7 +191,7 @@ The variables associated to a particular instance of a class.Also we can say, th
177
191
178
192
We can declared them in the special method of a class named **__init__**.
179
193
180
-
In our example of Car class, every instance of the Car class have their own set of model, color, speed associated with it. So, these are the instance variables(attributes)
194
+
In our example of Car class, every instance of the Car class have their own set of model, category, speed associated with it. So, these are the instance variables(attributes)
181
195
182
196
We use dot notation with class instance to access them. e.g.
183
197
```python
@@ -256,7 +270,7 @@ We use @classmethod decorator to tell python that it is a classmethod. By doing
0 commit comments