Created
March 25, 2023 11:13
-
-
Save kazimmsyed/b02294f0cd586c294e70f81d7f13117d to your computer and use it in GitHub Desktop.
How to work with decorators and Override function in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Override(x): | |
def new_func(*args,**kwargs): | |
print('>>>>>') | |
x(*args,*kwargs) | |
print('------') | |
return new_func | |
class Animal(): | |
def __init__(self,name): | |
self.name=name | |
def eat(self): | |
return "eating" | |
class Dog(Animal): | |
def __init__(self,name,spots): | |
Animal.__init__(self,name) | |
self.spots=spots | |
@Override | |
def eat(self): | |
print("Bow wow!",self.name,"is eating") | |
bear=Dog("Bear",True) | |
bear.eat() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment