Home Tutorials Python OOP Concepts self Keyword
self Keyword

self Keyword


7. self Keyword

In Python, self refers to the current object and is used to access instance data and methods. It is not a keyword enforced by the language, but it is the standard convention used in Python classes.

Syntax

class Demo:
    def show(self):
        print("method called")

Example

class Demo:
    def __init__(self, value):
        self.value = value
        
    def show(self):
        print(self.value)

obj = Demo(100)
obj.show()

Output

100
Example

🏋️ Test Yourself With Exercises

Take our quiz on self Keyword to test your knowledge.

Browse Quizzes »