Why should you convert your private class methods to static methods in Python whenever possible?
Experience Level: Junior
Tags: Python
Answer
When a method is decorated as static, it means that it is not using instance of a method. This way the reader of the method knows that the method is not dependent on the state of the class (class attributes).
Thanks to this it is easy to move the static methods to other classes, you know the code doesn't have any external dependencies besides those that are passed to a method by parameter.
This technique simplifies refactoring heavily. It makes the code more readable and maintainable.
Related Python job interview questions
Why should you use private and protected methods instead of defining all methods as public in Python?
Python JuniorWhat is a static method in Python?
Python JuniorHow do you comment out code in Python using multi-line comment?
Python JuniorHow do you comment out code in Python using single-line comment?
Python JuniorHow do you delete an item from a list in Python?
Python Junior