Using this example from http://docs.python.org/tutorial/classes.html#class-objects:
class MyClass:
"""A simple example class"""
i = 12345
def f(self):
return 'hello world'
According to those docs, f is an attribute reference that returns a function object.
Is there any shorter way of saying what f is? Can I call it a method of a class (note how I didn't say "class method" which is incorrect)? Or a function defined within a class? Or an instance method?
In other words, what's the formal short-hand term for f in terms of its relation to MyClass?
If you're referring specifically to the f
returned by MyClass.f
, then f
is an unbound method of MyClass. Or at least that's what the REPL calls it:
>>> MyClass.f
<unbound method MyClass.f>
In general though, I don't think anyone would fault you for simply calling it a "method", plain and simple. Or, in terms of its relation to MyClass, a method of MyClass.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With