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.

Python for beginners
Python for beginners

Are you learning Python ? Try our test we designed to help you progress faster.

Test yourself