Python Class

Data structure

Besides list, tuple, string, dictionary, set are data structure, you can define class that has attributes
For example
1
class car(object):
2
wheel_number=4
3
seal_row_number=2
4
5
def __init__(self,brand):
6
self.brand=brand
Copied!
wheel_number, seal_row_number are class attributes, class attributes can be of any data type, include
list, tuple, string, dictionary and set
You notice class can also have methods, __init__() is called constructor method, it runs when instantiating a class, for example
small_car=car("toyota")
small_car.brand
'toyota’
small_car.seal_row_number
2
Last modified 1yr ago
Copy link