Python Day 7 (2) Classes and instances (1)

Source: Internet
Author: User

One: Object-oriented Programming

1 Object-oriented programming--object oriented programming, short for OOP, is a programming idea. OOP takes objects as the basic unit of a program, and an object contains functions for data and manipulating data.

2 object-oriented versus process-oriented differences:

A process-oriented programming treats a computer program as a set of commands, that is, the sequential execution of a set of functions. In order to simplify the program design, the process will continue to cut the function into sub-function, that is, the large function by cutting into small block function to reduce the complexity of the system.

B Object-oriented programming treats a computer program as a collection of objects, and each object can receive messages from other objects and process those messages, and the execution of a computer program is a series of messages passing between objects.

3 in Python, all data types can be treated as objects and, of course, objects can be customized. The custom object data type is the concept of class in object-oriented.

4

 class studentdef __init__ (self, name, score): Self.name = name Self.score = score def print_score '%s:%s '% (Self.name, self.score))                

bart = Student(‘Bart Simpson‘, 59)lisa = Student(‘Lisa Simpson‘, 87)bart.print_score()lisa.print_score()

StudentThis data type should be treated as an object that owns name and both score properties. If you want to print a student's score, you must first create the corresponding object for the student, and then send the object aprint_score
b A message to the object is actually called the object corresponding to the associated function, which we call the method of the object
C Object-oriented design idea is to abstract the class, according to the class to create instance.

Python Day 7 (2) Classes and instances (1)

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.