What is the use of self in Python?

Last updated 3 weeks, 6 days ago | 21 views 75     5

Tags:- Python

Python | Self

Self is used to represent the instance of the class. With this keyword, you can access the attributes and methods of the class in python. It binds the attributes with the given arguments.

class Student:
     def __init__(self, name, roll): 
          self.name = name
          self.roll = roll
     def display(self):
          print("Name: ", self.name)
          print("Roll: ", self.roll)