Object-oriented Python

Source: Internet
Author: User

Object-oriented Python

Object-oriented programming is a programmatic approach that needs to be implemented using classes and objects.

Therefore, object-oriented programming is actually the use of "class" and "object".

A class is a template that can contain multiple functions and functions in a template.

Objects are instances created from templates that can execute functions in a class through an instance object

    • Class is a keyword that indicates that classes
    • Create the object, and then add parentheses to the class name

PS: A function in a class The first argument must be self (see in detail: Encapsulation of the three main characteristics of a class)
A function defined in a class is called a "method"

#Create ClassclassFoo:defBar (self):Print 'Bar'     defHello (self, name):Print 'I am%s'%name#Create object from class Foo objobj =Foo () obj. Bar ()#Execute Bar MethodObj. Hello ('Wupeiqi')#Execute the Hello method

Object-oriented three major features:

The three major characteristics of object-oriented are: encapsulation, inheritance and polymorphism.

First, the package

Encapsulation, as the name implies, encapsulates the content somewhere and then calls the content that is encapsulated somewhere.

Therefore, when using object-oriented encapsulation features, you need:

    • Encapsulate content somewhere
    • To invoke the encapsulated content from somewhere

First step: encapsulate the content somewhere

Object-oriented Python

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.