Can I define "static" (like in C++) methods in Python?

Seo Sanghyeon unendliche at hanmail.net
Fri Apr 11 00:35:56 EDT 2003


> Can I define methods which are attributes of class and not attributes of
> instance?

Yes. It is called staticmethod().

class Math:
  def add(x, y):
    return x + y
  add = staticmethod(add)

Math.add(2, 3)




More information about the Python-list mailing list