python--Object-Oriented programming

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.