Class Car (object): # model, template
def __init__ (self, Color, window):
# constructor, the class executes it at initialization time, the order does not matter, can be written at the bottom
# If your class is going to pass some arguments when instantiating it, then you need to write the arguments in the __init__ function.
Self.color = Color # Bus.color automatically passes the bus to self , which represents this class of objects
Self.window = window # Binding property
Print (' Execute me ... ‘)
def run (self):
Print (Self.color)
Print (Self.window)
Print (' The car is running ... ‘)
def my_self (self):
Print (' I am a car, my color is%s, I am%s '% (Self.color, Self.window))
def __del__ (self):
# destructor, which executes when this instance is destroyed
Print (' over ... ')
# make the model into a real car, this process is called instantiation.
Bus = Car (' Yellow ', ' 4 Open Door ') # instantiation
# instance refers to something that is specifically created, and what is instantiated through the class is an example.
# object is instance bus
Bus.run ()
Bus.my_self ()
python--Object-oriented programming