Static method: use the function without adding the attributes required for a new instance

Static method: use the function without adding the attributes required for a new instance

Have you ever had a function in your class that doesn’t access any properties of a class but makes sense that it belongs to the class? You might find it redundant to instantiate the class to use that function. That is when you can turn your function into a static method.

All you need to turn your function into a static method is the decorator ‘@staticmethod’. Now you can use the function without adding the attributes required for a new instance. Find the example below.

Search

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran