By default, any class we create will permit the following four behaviors with respect to attributes:
- To create a new attribute and set its value
- To set the value of an existing attribute
- To get the value of an attribute
- To delete an attribute
We can experiment with this using something as simple as the following code. We can create a simple, generic class and an object of that class:
>>> class Generic: ... pass ... >>> g = Generic()
The preceding code permits us to create, get, set, and delete attributes. We can easily create and get an attribute. The following are some examples:
>>> g.attribute = "value" >>> g.attribute 'value' >>> g.unset Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'Generic&apos...