5.initializing a class
define the init()function of the Car class to take four inputs:self,model,color,and mpg.
Assign the last three inputs to member variables of the same name by using the self keyword.
Then,modify the object my_car to provide the following inputs at initialization:
model = "DeLorean"
color = "silver"
mpg = 88
you don't need to include the self keyword when you create an instance of a class ,because self gets added to the beginning of your list of inputs automatically by the class definition.
class Car(object):
condition ="new"
def init(self,model,color,mpg):
self.model = model
self.color = color
self.mpg = mpg
my_car =Car("DeLorean","silver",88)
def 要縮格梧宫,不能頂頭寫接谨,不然程序會出錯(cuò)