PythonOOPs Concepts
Types of Methods
Types of Methods in Python
In Python, methods define the behavior of a class and determine how data is accessed and modified. Based on what they operate on—object data, class-level data, or no data at all—Python provides three types of methods:
- Instance Methods
- Class Methods
- Static Methods
Variables and Their Scope
Before exploring method types, it is important to understand variable scope:

Instance Methods
What Are Instance Methods?
- Instance methods are the most common type of methods
- They use
selfas the first parameter - They operate on instance variables
- Each object maintains its own independent state
Example
class Computer:
brand = "Telusko AI"
def __init__(self, cpu, ram, ssd):
print("init called")
self.cpu = cpu
self.ram = ram
self.ssd = ssd
def config(self):
print("config :", self.cpu, self.ram, self.ssd)
com1 = Computer("i5", "16GB", "512GB")
com2 = Computer("i9", "96GB", "2TB")
com1.config()
com2.config()
print(Computer.brand)Output
init called
init called
config : i5 16GB 512GB
config : i9 96GB 2TB
Telusko AIKey Points
selfrefers to the current object- Instance methods work with object-specific data
- Changes affect only that object
Class Methods
What Are Class Methods?
- Defined using the
@classmethoddecorator - Use
clsas the first parameter (by convention) - Work with class variables
- The class itself is passed automatically, not an object
Example
class Computer:
brand = "Telusko AI"
def __init__(self, cpu, ram, ssd):
self.cpu = cpu
self.ram = ram
self.ssd = ssd
def config(self):
print("config :", self.cpu, self.ram, self.ssd)
@classmethod
def info(cls):
return cls.brand
print(Computer.info())Output
Telusko AIKey Points
- Class methods operate on shared data
- Modifying class variables affects all objects
- Often used for factory methods or class-level information
Static Methods
What Are Static Methods?
- Defined using the
@staticmethoddecorator - Do not receive
selforcls - Independent of both object and class state
- Used as utility or helper functions
Example
class Computer:
@staticmethod
def gb_to_bytes(gb):
return gb * (1024 ** 3)
print(Computer.gb_to_bytes(16))Output
17179869184Key Points
- No access to instance or class variables
- Logically related to the class
- Improves code organization and readability
Impact of Variable Scope
- Modifying a class variable using the class name affects all objects
- Modifying an instance variable using
selfaffects only that object - Instance and class variables exist in separate namespaces

Summary
- Python provides three types of methods: instance, class, and static.
- Instance methods operate on object-specific (instance) data using
self. - Class methods operate on shared class-level data using
cls. - Static methods act as utility functions, independent of class and object state.
- Using the appropriate method type results in cleaner, more maintainable, and well-structured object-oriented code.
Written By: Muskan Garg
How is this guide?
Last updated on
