(my 'e' key has been failing me recently)
Normal Python has classes which possess member functions (methods). Normal methods always take an initial parameter (usually called 'self') which refers to the instance of the class. For example:
class Ball(object):\n def __init__(self):\n self.x = 0\n\n def bounce(self, distance):\n self.x += distance\n\nbasketball = Ball()\nbasketball.bounce(3)
Inside 'bounce' (when we call it), 'self' refers to the basketball object instance, so you can manipulate it. Sometimes, however, you want a method which doesn't care about the instance, only the class. Often, these are constructors:
class Ball(object):\n def __init__(self):\n self.x = 0\n self.y = 0\n\n def displaced(cls, x, y):\n b = cls()\n b.x = x\n b.y = y\n return b\n displaced = classmethod(displaced)\n\nbasketball = Ball.displaced(3, 4)\nbasketball.bounce(3)
classmethod() takes what would have been a normal member function and makes it a class method. Class methods don't receive an instance as the first argument, but a class instead (classes are objects in Python). You have to pass in the class for the method to work on it. The above is pretty trivial--we could have just written
b = Ball() instead of
b = cls(), but once you start subclassing, you can take advantage of the generic nature of cls.
Hope that helped <:)