WHAT IS SELF KEYWORD IN PYTHON | QA SDET | TEST AUTOMATION
Автор: Viplove QA - SDET
Загружено: 2025-05-24
Просмотров: 509
Описание:
🔹 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.
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: