I am curious about why we need the @staticmethod
decorator to declare method as static.
I was reading about static methods in Python, and I came to know that a static method can be callable without instantiating its class.
So I tried the two examples below, but both do the same:
class StatMethod:
def stat():
print("without Decorator")
class StatMethod_with_decorator:
@staticmethod
def stat():
print("With Decorator")
If I call the stat()
method on the class directly, both print/show the values below:
>> StatMethod.stat()
without Decorator
>> StatMethod_with_decorator.stat()
With Decorator