What’s the significance of this “self”?? Is it a temporary variable used to denote the object when it’s created(later)?
While creating a class we are using a parameter "self"
self represents the instance of the class. By using the “self” keyword we can access the attributes and methods of the class in python.
But “self” is just a convention the first argument of any method in a class is treated like the class’s instance although its a strong convention to name it as self for example.
class Restaurant(object):
bankrupt = False
def open_branch(this):
if not this.bankrupt:
print(“branch opened”)
here “this” argument is the instance of the class used to access its variables and methods although its a convention to take it as “self” but we can name it anything.
Hey Himanshu, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.
Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.