Python Tutorial: Slots, Avoiding Dynamically Created Attributes



Computer Slots The attributes of objects are stored in a dictionary "__dict__". Like any other dictionary, a dictionary used for attribute storage doesn't have a fixed number of elements. In other words, you can add elements to dictionaries after they have been defined, as we have seen in our chapter on dictionaries. This is the reason, why you can dynamically add attributes to objects of classes, you have created.

We recommend to continue with our chapter "Python3 Slots" of our Python3 tutorial. It's compatible with version 2.x anyway.