This article to share the content is about the Python object-oriented instance properties and class attributes, has a certain reference value, the need for friends can refer to
Because Python is a dynamic language, creating an instance from a class can bind properties arbitrarily.
The way to bind properties to an instance is through an instance variable, or through the self variable:
Class Student (object): def __init__ (self,name): self.name = names = Student (' Jeff ') print (s.name) #jeff
When we define a class property, this property is categorized as all but all instances of the class
can be accessed. To test:
>>> class Student (object): ... name = ' Student ' ...>>> s = Student () >>> print (s.name) student>>> print (student.name) Student >>> s.name = ' Jeff ' >>>>>> print (s.name) jeff>>> print (student.name) student> >> del s.name>>> print (s.name) student>>> print (student.name) Student
As can be seen from the above example, when writing a program, do not use the same name for instance properties and class properties, because instance properties of the same name will mask the class properties, but when you delete the strength attribute, and then use the same name, access to the class property