Big pressure ah
To pump myself up, fuel oil Piggy them!
Today brainwashing verse: Come, learn in the future to find a high-paying job, so as to be arbitrary, or you can pay with a lock to be!
Object-Oriented Programming
A process-oriented programming
The core process-oriented programming is the process of the word, it refers to the process steps to resolve the problem, which is to do what and then what ......
Based on the idea to write a program like process-oriented programming in assembly line design, it is a mechanical way of thinking.
- Pros: complex processes of the problem, and then simplify
- Disadvantages: poor scalability
Yes, more than the things we talked about before.
fart!
For I did say that.
Today we talk about the more Diao things, object-oriented programming, looking at your wife hit the code, understand it, ha ha, do not listen to me, I pull a calf, and object-oriented programming is to give examples of something into a object.
Second, the object-oriented programming
The core object-oriented programming word is the object, the object is a combination of features and skills.
Object-oriented programming is based on the idea of programming, is like creating a world, you are the God of this world, God is thinking way in style.
- Advantages: scalability
- Disadvantages: complexity than process-oriented programming
Give you a good explanation of what is object-oriented programming.
Classes and Objects
A, classes and objects
- Class meaning: the type, category, categories
The object is a combination of characteristics and skills, I may have height and weight, and you have height and weight, so you can say you are like me, but you will not say you like Tun Town. And you and I can actually be said to be a class, and you can not say that a system of elective classes, given the definition of class: Class is a series of similar objects and features a combination of skills.
In the real world: first, the existence of a concrete object, and then with the development of human civilization was the concept of classification, since the real world there is the concept of class, the program also must have Python class concept, but in a Python program : You must first define the class, and then call the class to create objects.
Second, the real world is defined classes and objects
Me, one of the most common type, it is human.
Each of us has a built-in attribute born, have hands and feet, have brains (though I did not), who has some property. Everyone is an instance of this class is an object. Do you think that we are the same yet? Of course not, when we are born the same, but then, we have learned a lot of other things, which is later added an object's properties, plus our own, which resulted in various colors of each object type, just like the Oriental scholar learned to internal forces, he learned Japanese ninja chakra, Western monks learned the mental strength and so on.
This is the result of the same object after different operations generated. They all share the same attribute class, but also has its own unique attributes.
Third, objects and classes defined in the program
3.1 Definitions class
# 注意类中定义变量使用驼峰体
class OldboyStudent():
school = 'oldboy'
def choose_course(self):
print('is choosing course')
This is the definition of a class
- Once defined functions, function only detect syntax does not execute code, but the definition of class, the class body code to be executed immediately in the class definition phase and will produce a class name space, which means that the class itself is actually a container / name space is used to store the name, which is one type of use
3.2 define the object
stu1=OldboyStudent() # 调用类会得到一个返回值,该返回值就是类的一个具体存在的对象/实例
print(stu1.school)
This is an example of a class, create an object.
Then how do we learn ninjutsu, chakra learn it? ?
Learn your grandmother does, what little things Chinese people to learn Japanese, I studied Falun Gong
Unique features custom objects
This method was first introduced
print(stu.__dict__)
This can directly view the class defined attributes show up in the form of a dictionary.
print(stu1.__dict__)
And this object can not see anything, why, because he's just an empty thing, any property you use this object calls, are called to class, so there are empty, you can still to call things.
How can that make this dictionary has things?
Of course, if the latter is your thing, ah.
such as
stu1.skill='法 轮 功'
print(stu1.__dict__)
This time the results of your printing is not empty, but more out of a skill called the Falun Gong, this time you do not have an impact on class, other objects do not have this property, because it is the result of your own development, so I said before can understand the meaning of the colors of each object type yet?
First, find the order of attributes
- First look for from their own, did not find to find a class, the class will be no error. Find a property that is the object of the order: self - "Class -" error