object-oriented programming @property def width(self)return self __width @property def height(self)return self __height @property def colors(self)return set(self __colorscopying collections when returning data attribute from an object we need to be aware of whether the attribute is of an immutable or mutable type it is always safe to return immutable attributes since they can' be changedbut for mutable attributes we must consider some trade-offs returning reference to mutable attribute is very fast and efficient because no copying takes place--but it also means that the caller now has access to the object' internal state and might change it in way that invalidates the object one policy to consider is to always return copy of mutable data attributesunless profiling shows significant negative effect on performance (in this casean alternative to keeping the set of unique colors would be to return set(self __data values(){self __backgroundwhenever the set of colors was neededwe will return to this theme shortly def __getitem__(selfcoordinate)assert len(coordinate= "coordinate should be -tupleif (not ( <coordinate[ self widthor not ( <coordinate[ self height))raise coordinateerror(str(coordinate)return self __data get(tuple(coordinate)self __backgroundthis method returns the color for given coordinate using the item access operator ([]the special methods for the item access operators and some other collection-relevant special methods are listed in table we have chosen to apply two policies for item access the first policy is that precondition for using an item access method is that the coordinate it is passed is sequence of length (usually -tuple)and we use an assertion to ensure this the second policy is that any coordinate values are acceptedbut if either is out of rangewe raise custom exception we have used the dict get(method with default value of the background color to retrieve the color for the given coordinate this ensures that if the color has never been set for the coordinate the background color is correctly returned instead of keyerror exception being raised