First, instance properties
Python is a dynamic language, and an instance created from a class can be arbitrarily bound to a property.
1>>>classStudent (object):2...def __init__(self, name):3... Self.name =Name # Properties required for each instance4 ... 5>>> s = Student ('Jack')6>>> S.score = 90 # Arbitrary binding properties7>>>S.name8 'Jack'9>>>S.scoreTen90
Second, class properties
The attribute is defined directly in class, which is the class attribute and belongs to the Student
class.
1>>>classStudent (object):2... Name ='Jack' #Class Properties3 ... 4>>> Student.name#Get class Properties5 'Jack'6>>> s =Student ()7>>> S.name#Get class Properties8 'Jack'9>>> S.name ='Mike' #Adding instance PropertiesTen>>> S.name#Get Instance Properties One 'Mike' A>>> Student.name#Get class Properties - 'Jack'
When writing a program, never use the same name for instance properties and class properties, because instance properties of the same name will mask class properties, but when you delete an instance property and then use the same name, the class attribute is accessed.
Python object-oriented six class properties and instance properties