Originally posted on Medium.
For my first Medium article, weβre going to go into a quick and easy way to speed up your Python code (and pass those pesky HackerRank tests where youβre just a bit short on time!), as well as some of the technical implementation details for the curious.
__slots__
is an attribute you can add to a Python class when defining it. You define slots with the possible attributes that an instance of an object can possess. Hereβs how you use __slots__
: