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
@@ -80,8 +80,6 @@ To name a `class` in Python the convention is to start with capital letter like:
80
80
## class keyword and __init__ method
81
81
Everything in Python is a class. like **list**, **int**, **str**, **tuple**, **functions**, **sys** etc. To create a user defined object we use **class** keyword in Python. The special method **__init__** is used to initialize an object of that class.
82
82
83
-
---
84
-
85
83
### An example of a `Car class`:
86
84
Let's say, we need to create a record of cars manufactured by the Tata Motors. The data and data related to car are as mentioned below.
87
85
@@ -95,7 +93,6 @@ Year = 2022
95
93
|Harrier|Black|180| December|
96
94
|Harrier|Dark Grey|180| December|
97
95
98
-
99
96
**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**.
100
97
101
98
For this we will create the Car class in Python like below:
@@ -170,8 +167,6 @@ print(car.name)
170
167
print(car.speed)
171
168
```
172
169
173
-
---
174
-
175
170
### Class variables:
176
171
The variables associated with all the the instances of a class. They are shared by all the instances of that class.
177
172
@@ -232,6 +227,8 @@ We use @classmethod decorator to tell python that it is a classmethod. By doing
232
227
233
228
### Static method
234
229
230
+
---
231
+
235
232
## Helpful In-build Methods:
236
233
### dir(): List all the data and methods associated with `instance car1` and `class Car`.
237
234
```python
@@ -324,6 +321,8 @@ print(Animal.__dict__)
324
321
{'__module__': '__main__', '__init__': <function Animal.__init__ at 0x7f295e98ef70>, '__str__': <function Animal.__str__ at 0x7f295e935040>, 'walk': <function Animal.walk at 0x7f295e9350d0>, 'jump': <function Animal.jump at 0x7f295e935160>, 'speak': <function Animal.speak at 0x7f295e9351f0>, '__dict__': <attribute '__dict__' of 'Animal' objects>, '__weakref__': <attribute '__weakref__' of 'Animal' objects>, '__doc__': None}
0 commit comments