In "Making and Calling Classes," earlier in this chapter, we describe how to add an attribute to a class, and the preceding section describes how to change the value of a class or instance attribute. You can also add a data attribute (and value) to an instance that you've created. Just write code like this:
REMEMBER This attribute is stored in the instance's namespace, so the class won't know about this attribute, as illustrated here:
Traceback (most recent call last):
File "<stdin>", line 1, in ? AttributeError: class Lab has no attribute 'coat color'
Was this article helpful?