Untitled
unknown
plain_text
2 years ago
1.3 kB
12
Indexable
#----------------------------CONSTRUCTORS-----------------------------------------
# class Person:
# name="Ansh"
# occupation="Product Manager"
# def __init__(self,n,o):
# print("Chut ka chakkar, maut se takkar")
# self.name=n
# self.occupation=o
# def info(self):
# print(f"{self.name} is {self.occupation}")
# a=Person("Ansh","PM")
# b=Person("Divya","Scientist")
# a.info()
# b.info()
# # c=Person(1,2,3) c goes as self argument so this will give an error since 4 arguments are being passed instead of 3
#----------------------------DECORATORS-----------------------------------------
'''
def greet(fx):
def mfx(*args, **kwargs):
print("Good Morning")
fx(*args, **kwargs)
print("Thanks for using this function")
return mfx
@greet
def hello():
print("Hello world")
@greet
def add(a, b):
print(a+b)
# greet(hello)()
hello()
# greet(add)(1, 2)
add(1, 2)
import logging
def log_function_call(func):
def decorated(*args, **kwargs):
logging.info(f"Calling {func.__name__} with args={args}, kwargs={kwargs}")
result = func(*args, **kwargs)
logging.info(f"{func.__name__} returned {result}")
return result
return decorated
@log_function_call
def my_function(a, b):
return a + b
'''
Editor is loading...
Leave a Comment