Advertisement
elena1234

types of methods ( Python )

Feb 4th, 2022 (edited)
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. class Cat:
  2.     species = "mammal"
  3.     def __init__(self, name, age):
  4.         self.name = name
  5.         self.age = age
  6.    
  7.     def eating(self): # Instance method
  8.         return (f" {self.name} is eating...")
  9.      
  10.     @classmethod  
  11.     def get_species(cls):
  12.         return cls.species
  13.    
  14.     @staticmethod
  15.     def info():
  16.         print("This is a class Cat")
  17.    
  18.    
  19. cat1 = Cat("Robi", 5)
  20. print(cat1.eating()) # Instance method
  21.  
  22. print(Cat.get_species()) # Class method
  23.    
  24. Cat.info() # Static method
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement