0

For example:

class A:
    factor = 2
    def salary(self):
         base_sal = 10000
         sal = base_sal*factor
         print("Your Salary:",sal)

    @classmethod
    def inc_factor(cls):
        cls.factor += 0.1

    def increase_factor():
        A.factor += 0.1
     

Why can't we just use A.increase_factor() rather than using the @classmethod as it will only function inside the A class and why is worth passing class argument for doing the same as normal method?

  • 1
    Primarily because they will be usable in subclasses. See [What is the purpose of class methods?](https://stackoverflow.com/questions/38238/what-is-the-purpose-of-class-methods), and also https://stackoverflow.com/questions/136097/difference-between-staticmethod-and-classmethod and https://stackoverflow.com/questions/12179271/meaning-of-classmethod-and-staticmethod-for-beginner – mkrieger1 Sep 17 '21 at 15:43

0 Answers0