@classmethod receives the class as the first argument (cls). @staticmethod does not receive anything automatically.
Instance method (regular):
1class User:2 def __init__(self, name):3 self.name = name45 def greet(self): # self = instance6 return f"Hello, {self.name}"
@classmethod:
1class User:2 users = [] # Class attribute34 def __init__(self, name):5 self.name = name6 User.users.append(self)78 @classmethod9 def count(cls): # cls = class10 return len(cls.users)1112 @classmethod13 def from_string(cls, user_str): # Alternative constructor14 name = user_str.split(",")[0]15 return cls(name)1617User.from_string("Alice,25")18print(User.count()) # 1
@staticmethod:
1class Math:2 @staticmethod3 def add(a, b): # No self/cls4 return a + b56print(Math.add(2, 3)) # 5