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()
Student
This 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)