We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Also, since the method does not reference any class or instance attributes, you could make it a static method by using the @staticmethod decorator, which provides more flexibility by allowing you to call the method without creating a Calculator instance.
class Calculator:
@staticmethod
def power(n, p):
if n < 0 or p < 0:
raise ValueError('n and p should be non-negative')
return n ** p
Day 17: More Exceptions
You are viewing a single comment's thread. Return to all comments →
Also, since the method does not reference any class or instance attributes, you could make it a static method by using the @staticmethod decorator, which provides more flexibility by allowing you to call the method without creating a Calculator instance.