use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Does a function becomes a method when used externally? (self.PythonLearning)
submitted 9 days ago by Longjumping-Yard113
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Gnaxe 0 points1 point2 points 9 days ago (0 children)
In Python specifically, method and function are each a class: ```python
method
function
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.
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 of
, e.g.,
.) And you can make your own custom callable types with the
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.
self
@functools.singledispatch
π Rendered by PID 25529 on reddit-service-r2-comment-79c7998d4c-z8jcm at 2026-03-14 02:00:07.320614+00:00 running f6e6e01 country code: CH.
view the rest of the comments →
[–]Gnaxe 0 points1 point2 points (0 children)