What is the reason behind writing “self” ?
def sayHi(self):
print(“Hi”);
Class related doubt
Hey @yashikakhurana00, because if we want to access class data members in classes in python there is no direct way to aceess them, you need to use self.data_member_name. So for every function its a thumb rule first argument will be self always.
Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section.
1 Like
Thank you for answering.
Is this applicable even when we aren’t trying to access any data member of the class, like here we are just printing “Hi”. ?
Hey @yashikakhurana00, yes no matter you use/access data member of class in function, first argument will be self. always.
1 Like