Discover more from Daily Dose of Data Science
Use Slotted Class To Improve Your Python Code
If you want to fix the attributes a class can hold, consider defining it as a slotted class.
While defining classes, __𝘀𝗹𝗼𝘁𝘀__ allows you to explicitly specify the class attributes. This means you cannot randomly add new attributes to a slotted class object. This offers many advantages.
For instance, slotted classes are memory efficient and they provide faster access to class attributes. What's more, it also helps you avoid common typos. This, at times, can be a costly mistake that can go unnoticed.
Read more: StackOverflow.
Share this post on LinkedIn: Post Link.
Thanks for reading Daily Dose of Data Science! Subscribe for free to learn something new and insightful about Python and Data Science every day. Also, get a Free Data Science PDF (250+ pages) with 200+ tips.