+ 2
return self
What returns "return self"?
3 ответов
+ 6
Self is the convention name for the current instance that is being worked with. Return self basically returns the object that had its method called.
Example:
class A:
def __init__():
# blah blah
def fun():
return self
obj = A()
print(obj.fun())
# Outputs: <A object at someMemoryLocation>
+ 6
class a:
def q(firstarg):
print(firstarg)
@classmethod
def w(firstarg):
print(firstarg)
@staticmethod
def e(firstarg):
print(firstarg)
i = a()
i.q()
i.w() #a.w()
i.e('abc') #a.e('abc')
+ 1
Gami🇷🇴 but what is convention(in our case) and what current instance do you mean?
And is self the method or what you mean when saying"returns the object that it had basically returns the object that had its method called"?