Bullet Points:
Python is similar in class to JavaScript (regrets not looking at JS), only one "method is shared, and property is not shared"
classathletelist:def __init__( Self, a_name,a_dob=none,a_times=[]):Self.name=a_name Self.dob=A_dob self.times=a_timesdeftop3 (self):returnSorted (Set ([Float (sanitize (item)) forIteminchSelf.time]) [0:3] defadd_time (Self, Time): Self.times.append (Time)defadd_times (Self, Times): Self.times.extend (Times)
1. The __init__ method is equivalent to a constructor function
2. The first parameter of each method, self, refers to the current instance object
Python can, of course, inherit it.
classathletelist (list):def __init__(self,a_name,a_dob=none,a_times=[]): list. __init__ ([]) self.name=a_name Self.dob=a_dob self.extend (a_times)deftop3 (self):returnSorted (Set ([Float (sanitize (item)) forIteminchSelf]) [0:3] defAdd_time (self,time): Self.append (Time)defAdd_times (self,times): Self.extend (Times)
Similar to the inheritance of other languages, except that the syntax is not the same, and the constructor of the inherited class needs to be called in the constructor
Head Frist Python Reading notes sixth customizing data Objects