Python Learning Note 9: Object-oriented Programming, class

Source: Internet
Author: User

First, object-oriented programming

Object-oriented--object oriented programming, short for OOP, is a programming idea.

There is another kind of programming idea- oriented to process programming. The process-oriented idea is to make a project, a thing in a certain order, from start to finish, do what first, after what, until the end. This idea is better understood, in fact, it is also a person's way of doing things, our previous programming ideas are also using this idea.

  Object-oriented thinking is to divide a project, a thing into smaller projects, or into smaller parts, each part responsible for what aspects of the function, and finally by the combination of these parts become a whole. This kind of thought is more suitable for many people's Division of labor.

Ii. several concepts of object-oriented

 1, Class: Class

A class is an abstraction, blueprint, prototype for a class of objects that have the same properties

Class, which is a kind, a model

 2. Objects: Object

Object, that is, the concrete thing that the model created.

  3. Instantiation

Turn a class into a concrete object.

A class must be instantiated before it can be called in a program, and a class can instantiate multiple objects

 4. Encapsulation

The implementation details of some functions are not exposed, the assignment of data in the class, the internal invocation is transparent to the external user, which makes the class become a capsule or container, in which the bread implies the data and methods of the class.

  5. Inheritance

   A class can derive subclasses, properties, methods defined in the parent class, automatic quilt class inheritance

 6. polymorphic

    One method, multiple implementations. Polymorphic is not supported in Python

Third, the code example

1. Define a class

  

2. Inheritance

3. Overriding the construction method

Python Learning Note 9: Object-oriented Programming, class

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.