Python Tutorial, Release 3.9.5 (continued from previous page) >> >d.tricks # unexpectedly shared by all dogs ['roll over','play dead'] Correct design of the class should use an instance variable instead: If the same attribute name occurs in both an instance and in a class, then attribute lookup prioritizes the instance: Data attributes may be referenced by methods as well as by ordinary users (“clients”) of an object. In other words, classes are not usable to implement pure abstract data types. In fact, nothing in Python makes it possible to enforce data hiding — it is all based upon convention. (On the other hand, the Python implementation, written in C, can completely hide implementation details and control access to an object if necessary; this can be used by extensions to Python written in C.) Clients should use data attributes with care — clients may mess up invariants maintained by the methods by stamping on their data attributes. Note that clients may add data attributes of their own to an instance object without affecting the validity of the methods, as long as name conflicts are avoided — again, a naming convention can save a lot of headaches here. There is no shorthand for referencing data attributes (or other methods!) from within methods. I find that this actually increases the readability of methods: there is no chance of confusing local variables and instance variables when glancing through a method. Often, the first argument of a method is called$_{self}$. This is nothing more than a convention: the name$_{self}$has absolutely no special meaning to Python. Note, however, that by not following the convention your code may be less readable to other Python programmers, and it is also conceivable that a class browser program might be written that relies upon such a convention. 71 9.4. Random Remarks >>> classWarehouse : purpose = 'storage' region = 'west' >>> w1=Warehouse() >>> print(w1 .purpose, w1 .region) storage west >>> w2=Warehouse() >>> w2.region ='east' >>> print(w2 .purpose, w2 .region) storage east 9.4 Random Remarks classDog : def __init__ (self, name): self.name =name self.tricks =[] # creates a new empty list for each dog def add_trick(self, trick): self.tricks.append(trick) >> >d =Dog( 'Fido ') >> >e =Dog( 'Buddy') >> >d.add_trick( 'roll over') >> >e.add_trick( 'play dead') >> >d.tricks ['roll over'] >> >e.tricks ['play dead']