Python encapsulation, inheritance, and polymorphism

Source: Internet
Author: User

Data encapsulation, inheritance and polymorphism are the three main characteristics of object-oriented.

Data encapsulation:

In a class, such as the student class (initialization and name and score two properties), each instance has its own name,score of the data. We can access this data through functions, such as printing a student's score. Directly define an output function, output name and corresponding score.

However, since the student instance itself has this data, to access this data, there is no need to access from outside the function, you can directly within the student class to define the function of accessing the data, so that the "data" to encapsulate it, The functions of these encapsulated data are associated with the student class itself, which we call the method of the class. In this way, we look at the student class from the outside, just need to know that the creation of the instance needs to give name and score, and how to print, is defined within the student class, the data and logic is "encapsulated", the call is easy, but do not know the details of the internal implementation. One point, Python and static languages, Python allows you to bind any data to an instance variable, that is, for two instance variables, although they are different instances of the same class, the variable names you have may be different.

Python encapsulation, inheritance, and polymorphism

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.