Static Class Instance Methods Python
Static Class Instance Methods Python
1. Instance Method
Instance methods are the most common type of methods in Python classes. They take 'self' as the
class Dog:
self.name = name
def speak(self):
d = Dog("Tommy")
2. Class Method
Class methods take 'cls' as the first parameter and are used to access or modify class-level
class Dog:
species = "Canine"
@classmethod
def get_species(cls):
3. Static Method
Static methods do not take 'self' or 'cls' as the first parameter. They behave like regular functions
class Dog:
@staticmethod
def bark_sound():
return "Woof!"
Summary Table
Here is a summary comparing the different types of methods:
| Method Type | First Arg | Access Instance Data | Access Class Data |
Decorator |
|------------------|-----------|----------------------|-------------------|-----
-------------|
@classmethod |
@staticmethod |