Reputation: 171
I want to call a function from a python class but it would be necessary to initialize it so is there a way to call class methods without initializing the class. I have a js background I what I want is similar to this
class foo {
static calculate() {
return 'bar';
}
}
Upvotes: 2
Views: 957
Reputation: 2917
You can use @staticmethod
decorator to define static methods in python:
class Class:
@staticmethod
def method():
print("Method called")
Class.method()
Upvotes: 4