Mert Nuhoglu on 2009-08-08
fonksiyonlar birer obje olduğundan buna ihtiyaç var. javada buna gerek olmuyor, çünkü fonksiyonlar obje değil.
fonksiyon bağımsız bir instance olduğundan, hangi classa bağlı olduğunu bilmesi gerekir.
This link has been bookmarked by 24 people . It was first bookmarked on 04 Aug 2006, by Kazuo Moriwaka.
Since staticmethods return the underlying function with no changes, the example
calls are unexciting:
>>> class E(object):
def f(x):
print x
f = staticmethod(f)
>>> print E.f(3)
3
>>> print E().f(3)
3
Unlike static methods, class methods prepend the class reference to the
argument list before calling the function. This format is the same
for whether the caller is an object or a class:
>>> class E(object):
def f(klass, x):
return klass.__name__, x
f = classmethod(f)
>>> print E.f(3)
('E', 3)
>>> print E().f(3)
('E', 3)
çok kaliteli bir makale.
descriptors
Public Stiky Notes
fonksiyon bağımsız bir instance olduğundan, hangi classa bağlı olduğunu bilmesi gerekir.
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.