🧭this and self
Also known as this Keyword, self Parameter, self (Python)
Think of it like
It is like saying "me" in class. The word stays the same, but it means whoever says it.
Example
A bark method prints self.name. Called on Rex it says Rex. Called on Bella, the same code says Bella.
Definition
Example code
python
class Dog:
def __init__(self, name):
self.name = name
def bark(self):
print(self.name + " says woof")
Dog("Rex").bark()
# Rex says woof