+ 2

return self

What returns "return self"?

3rd Sep 2018, 6:37 PM
Ilyich
3 odpowiedzi
+ 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>
3rd Sep 2018, 11:52 PM
Gami
Gami - avatar
+ 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')
3rd Sep 2018, 7:32 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 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"?
5th Sep 2018, 1:43 PM
Ilyich