Let’s start with one very small and simple new feature. Here is the start of the definition of a simple
class Point: __slots__ = ("x", "y") def __init__(self, x=0, y=0): self.x = x self.y = y
When a class is created without the use of
__slots__, behind the scenes Python creates a private dictionary called
__dict__ for each instance, and this dictionary holds the instance’s data attributes. This is why we can add or remove attributes from objects. (For example, we added a
cache attribute to the
get_function() function earlier in this short cut.)
If we only need objects where we access the original attributes and don’t need to add ...