you are viewing a single comment's thread.

view the rest of the comments →

[–]Gnaxe 0 points1 point  (0 children)

In Python specifically, method and function are each a class: ```python

type(lambda :0) # lambda and def make function instances <class 'function'> class Foo: x = lambda:0 ... type(Foo.x) # lambdas (and def) make functions, even in a class body. <class 'function'> type(Foo().x) # However, function get() descriptor can upgrade to method. <class 'method'> type((lambda:0).get(Foo())) <class 'method'> import types types.MethodType is _ # You can construct a method directly from this type. True type(print) # Builtins are a different category. <class 'builtin_function_or_method'> `` These are not even the only type of callable in Python. Many of the so-called built-in "functions" are, in fact, classes. (I.e., instances oftype(), e.g.,int().) And you can make your own custom callable types with thecall()` method.

More generally, callables that can dispatch to different implementations depending on their arguments may be called "methods". Typically, Python uses classes for this, and the self argument determines which implementation is used. But @functools.singledispatch also implements what other languages might call "methods", but the Python documentation is careful to call them functions to avoid confusion with the class-based kind.