A: declaration of a class
keywords for class 1:
We've been exposed to the keyword from the first day of the first project, such as false True is not None of the return for while Elif
else import and so on, This is the language of a default grammar rules, the keyword to tell the computer under a letter or a paragraph
What is the code, what to use, to tell How to use the rules of the computer.
And class is the key word for classes, telling the system that I want to define a class. Let the system understand the rules of the class.
some of the code. Without a keyword to declare, the system does not know what the following code is.
2. Identifiers:
Identifiers are symbols used for identification. is set by itself. Related rules such as:
Anyway is according to the rules of their own settings to facilitate their own and others remember the understanding of the symbol!
3. The class name to inherit:
is a larger class, that is, the class you define is its subclass, you can inherit some functions and features from this parent class, and now
in use, the default is object. The relationship between the parent class and the subclass should be like a school's relationship with a class in this school, customizing
Righteousness class is a new class, class is not casually open, is in School in this environment to open. Otherwise, without the help of the school.
Class may be of no use. The newly opened class name is the identifier of the class.
Object is a super class. Just understand it as a rule of heaven. Whether it's eating, sleeping, hitting peas or doing missionary classes. In short, this
everything is in this world completed. Done under the rules of the world's operation.
object is like a rule of heaven for all classes!
Two: Object initialization in class:
1. Keywords for function:
Not much to say, write a function when the keyword. Because __init__ () is a function.
2.__init__ () functions and parameters:
There is a super class object in front of it, __init__ () is the one that was born in this superclass to initialize the object data.
a function, which is equivalent to the object A god born under a heavenly heaven with the ability to initialize, the parameters of the __init__ () function are determined
Righteous. Some of the features that this class has. To give a Li Zilai said:
Long long ago, the Heaven (object) was born, and the Lai (init function) was born. She has the ability to
Pinch improvised people. What is a human being? Female wa in the mind of people have imagined that people have such characteristics (attributes): Five
Officer, limbs, divided between men and women and so on. In short, this god (init) has set you some kind of sex, so no matter how you change it is
these genera Sex, she said you are oviparous, you will not be out of the egg. Otherwise, you're running the wrong movie, not in this class,
not this the objects in a class.
3. Initialize the data:
In this class, the INIT function has given some properties to the object, such as the student class, where an object in the student is a
name words, sex, height, weight these genera the sex. (Other attributes such as beauty and ugliness are not considered) but what is the name?
Sex What the hell? This will require initialization of the data!
Back to the myth, nu wa to create "people", including features, limbs, men and women and other attributes, but if she put these and other big
God They say that other great gods still don't know . man "is what, because the facial features are what, the limbs are what other great gods still do not know (by
This can be See the five senses, limbs and so on actually and "person" also is in the object), this time female WA to make the assignment, the scene made five
officer, four limb body then form a person, and this time the other great gods will understand, even if see a fatter person also can recognize out
this thing is the man made by Nu WA.
Three Use of the class:
1. Methods of the class:
Put on the class of vest called method, take off the vest called function.
A function set within a class that makes some steps about how to handle objects in a class.
1. References to class Property values:
A class is not a thing to be bored casually set up, but to treat some objects with the same attribute characteristics uniformly
of the one of the modules. So if people set up something like this to deal with some problems, then they're bound to want to deal with it.
some data. A reference to the Class property value is then made, since it is a class, and at some point of view, all of the
objects are is the same. It's only a little bit deeper to look at the property values of each object to distinguish each object, so we can
it Sample Acquisition data: Stu.name, first write which object and then click into a property, if only the object name,
then this object so many property systems You know which one do you want, simply give you the address of the object property store you find it yourself.
it! If there is only sex without object name, then your request is too unreasonable, the system will give you a false hint is no longer
Talk to you . out!
2. References to class methods:
If a class can only help people sort out data and then get people to cite it, it's better to build a dictionary directly.
All classes have a function called methods, you might want to get some sort of result that requires some sort of processing of objects in the class, then I
Straight then write the method. So what do you want to do with the object, then you tell the method directly that the method will be straight
Connect to you're a result. In this way, the method in the class is not a very useful and qualified assistant.
-----------class, which is probably a collection of objects with the same properties, and the ability to
for effective tube Management and something to do with something.
-----------object, there should be a reason to find something called an object. It's like me.
sitting, but too Yang said I was exercising, a sense of relativity.
-----Small white to the first impression of class and object/There is something wrong welcome passing the Great God!
A preliminary understanding of classes and objects in Python