In object-oriented programming, properties and methods are used very frequently. The following is a simple summary of the basic operation of the attribute.
In Python oop, attributes are typically manipulated in the following ways:
1, add attributes
2, modify the value of the property
3, get the value of the property
4, delete properties
Use a simple demonstration code to illustrate:
Class DemoClass:
Pass
obj = DemoClass ()
# Add new Attribute
Obj.value = 123
# get the value of attribute
Print (Obj.value)
# Modify the value of
Obj.value = 456
Print (Obj.value)
# Delete Attribute
Del Obj.value
Try
Print (Obj.value)
Except
Print ("error")
In the above code, each annotation explains what the corresponding operation means. In the above code, a simple demonstration of the properties of the Add, modify, get the value and delete several operations. The deleted property is definitely inaccessible, so a try statement avoids the error that might be thrown.
The results of the procedure are as follows:
Grey@desktop-3t80npq:/mnt/e/01_workspace/02_programme_language/03_python/03_oop/2017/08$python attr_demo.py
123
55W
Error
From the above results, roughly do the following summary:
1, directly to the object plus a property assignment operation, if the property does not exist will create a new property;
2, for the object's property assignment operation, if the property already exists, will modify the operation;
3, the property of the numerical acquisition, similar to the C language data structure;
4, the corresponding information cannot continue to be referenced after the property has been deleted.