Explain the importance of self in Python classes.
Answers
Answered by
3
Answer:
Self is used by the class to use a function.
Consider this program:
___________________________
class hey:
def __init__(self,name):
self.name=name
word=hey("me")
print(word.name)
__________________________
It returns:
__________________________
me
__________________________
Here function is being calling name directly though class with help of self.
Similar questions