Classes and objects:
To define a class:
Class Name:
Property
Method
To define the object of the class:
Object name of class = Class name ()
Class Property: Public and private, similar to C + + private and common, with the name of the variable added in front of __
Constructor: A function that initializes a class when it creates an object of the class. (its function is far more than the assignment so simple, thinking not to be limited)
Form: Def __init__ (self, other parameters)
Statement block
About which Self,self represents an instance of a class, representing the address of the current object. (According to my logic, because the function inside the class acts on the object of the class, then the object is itself, which is indicated by self)
Extension: About an instance of a class: Http://blog.sina.com.cn/s/blog_44178ab70100br3c.html.
Class method: You do not need to define an object, directly using the class name. function (), this function is a class method
instance method of the class: You need to define the object and then use the defined object name. function () to invoke, this is the instance method.
Destructors: Similar to constructors, except at the end of the day, and require self-invocation (constructors do not require active invocation, as defined by its definition)
static properties and Static methods:
1) They all belong to the class
2) static methods cannot access instance variables without passing in the self parameter.
What is an instance variable?
In the declaration of a class, a property is represented by a variable. This variable is called an instance variable and is declared inside the class declaration but outside of the other member methods of the class. Each object of the class maintains its own copy of an instance variable.
3) access directly through the class name
4) static method definition
Inheritance of the class:
Format:
Class name (base class name):
1 #这的确是一段值得研究的程序, here I just want to ask: As a subclass, you can use their own name, you can also use Dad's name to invoke the corresponding properties and methods2 #但是, if the subclass has properties and methods of the same name as the father, it will be replaced by the parent class's own name. 3 classCitizen:4 def __init__ (self):5Citizen. idcard='515611'6Citizen.name='Naruto'7Citizen.age= -8 def KK (self):9 Print (citizen. Idcard,citizen.name,citizen.age)Ten One classStudent (citizen): A def __init__ (self): -Student.number='123123' -Student.room='153' theStudent.age= the - def KK (self): - #如何输出以前的值? Still using citizen? Or with a student? It seems to be all. - Print (citizen. Idcard,citizen.name,citizen.age,student.number,student.room,student.age) + -# c=Citizen () + # C.KK () AD=student () at D.kk () -# Print (Citizen. Idcard)
Python object-oriented programming first projectile