Python OOP Methods Explained

Day 17 of my Python Full Stack journey. ✅ Today's topic: The 3 types of methods in OOP. Most beginners only know one. Here's all three explained simply. Here's what I typed today: class Student: school = "Acharya Institute" # class variable def __init__(self, name, marks): self.name = name # instance variable self.marks = marks # Instance method — works with one object def result(self): return f"{self.name}: {'Pass' if self.marks >= 50 else 'Fail'}" # Class method — works with the class itself @classmethod def school_name(cls): return f"School: {cls.school}" # Static method — independent, no self or cls @staticmethod def passing_marks(): return "Passing marks: 50" s1 = Student("Punith", 88) print(s1.result()) # instance method print(Student.school_name()) # class method print(Student.passing_marks()) # static method Simple rule: → Instance method — needs object data (use self) → Class method — needs class data (use cls) → Static method — needs neither. Just a helper function. Did you know all 3 types of methods before reading this? #PythonFullStack #Day17 #OOP #BuildingInPublic #100DaysOfCode #Bangalore

  • graphical user interface, text, application, chat or text message

To view or add a comment, sign in

Explore content categories