WHAT IS SELF KEYWORD IN PYTHON | QA SDET | TEST AUTOMATION

Опубликовано: 16 Июнь 2026
на канале: Viplove QA - SDET
535
3

🔹 What is self?

self refers to the current instance of the class.

It is used to access variables and methods within the class.



---

🟦 Why is self needed?

Python doesn't use this like some other languages.

It must be explicitly declared as the first parameter in instance methods.



---

🔸 Example:

class Person:
def __init__(self, name):
self.name = name # assign instance variable

def greet(self):
print(f"Hello, my name is {self.name}")

Usage:

p = Person("Alice")
p.greet() # Output: Hello, my name is Alice


---

🟩 Key Points:

self is not a keyword, just a naming convention (but recommended).

Without self, the instance variables won’t be linked to the object.

You can name it anything, but self is standard.