self

This represents the instance of the class
This is not a keyword.


class Student: 
    def __init__(self, name, age):
        # 'self' refers to the specific object being created
        self.name = name
        self.age = age

    def introduce(self):
        # Methods use 'self' to access the object's data
        return f"My name is {self.name} and I am {self.age} years old."

    def birthday(self):
        # 'self' lets the method modify the object's state
        self.age += 1
        return f"Happy birthday, {self.name}! You are now {self.age}."

# Using the class
s1 = Student("Alice", 20)
print(s1.introduce())

print(s1.birthday())
print(s1.introduce())



© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext