![]() | New-style classes allow static methods (methods that can be called without having an instance) class Point(object): _counter = 0 def __init__(self, x, y): self.x = x; self.y = y; Point._counter += 1 def ncopies(): return Point._counter ncopies = staticmethod(ncopies) |
![]() | Calls:
>>> Point.ncopies() 0 >>> p = Point(0, 0) >>> p.ncopies() 1 >>> Point.ncopies() 1 |
![]() | Cannot access self or class attributes in static methods |