|
|
|
|
|
by emidln
4862 days ago
|
|
Methods are type specialized functions, just syntactic sugar for calling functions with a context (provided by an instance of the required type) that you defined elsewhere. class Foo(object):
def __init__(self, bar):
self.bar = bar
def something(self, arg):
return [self.bar, arg]
I can do this: assert(Foo('spam').something('eggs') == Foo.something(Foo('spam'), 'eggs')
But I could also do this: assert(Foo('spam').something(Foo('ham'), 'eggs') == ['ham', 'eggs'])
|
|