Types of Methods in Python Classes :
- Instance Method
- Class Method
- Static Method
1. Instance Method
Definition:
Instance methods use the self keyword and work with instance variables.
Purpose:
To modify or access the object’s attributes.
Program:
2. Class Method
Definition:
Class methods use the @classmethod decorator and the cls keyword.
Purpose:
To access or modify the class variables.
Program:
3. Static Method
Definition:
Static methods use the @staticmethod decorator. They do not use self or cls.
Purpose:
To perform utility tasks that do not access instance or class variables.
Program:
Output :
0 Comments