What is the difference between Instance, Class, and Static Methods deep dive?

Sunil Kumar
5 min readJun 24, 2022

What is a python class?

Classes provide a means of bundling data and functionality together. Creating a new class, allows a new instance of that type to be made. Each class instance can have attributes attached to it for maintaining its state. Class instances can also have methods for modifying their state.

The classes can have three types of methods like Instance, Class, and Static Methods.

What are Instance, Class, and Static Methods?

let's first see with a toy class example:

class ExampleClass:    def __init__(self):
return 'instance method called', self
@classmethod
def class_method(cls):
return 'class method called', cls

@staticmethod
def static_method():
return 'static method called'

You just saw how to create the Instance, Class, and Static Methods for a class.

But before going further let's first understand what are class variables/attributes?

The Class attributes can be of two types

  • Instance variables: They are declared inside the constructor i.e. ( __init__ ) method…

--

--

Sunil Kumar
Sunil Kumar

Written by Sunil Kumar

With an extensive professional experience spanning over 16 years in the IT industry, I am a seasoned expert in AWS Cloud, DevOps, FastAPI, and Python.

No responses yet