Do you know what are python decorators?



Do you know what are python decorators?..

Answer / Harsh Kumar

Python decorators are a way to modify the behavior of functions or classes by attaching them before or after the function or class definition. They allow you to add additional functionality, control access, or change the execution flow without modifying the original function or class code. Here's an example:n```pythonndetails = []ndef log_details(func):n def wrapper(*args, **kwargs):n result = func(*args, **kwargs)n details.append((func.__name__, args, kwargs, result))n return wrappernn@log_detailsndef add(a, b):n return a + bnnadd(2, 3) # Executes the function and logs details about itnprint(details)

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

find max length of any given sublist?

1 Answers  


Is google made with python?

1 Answers  


Which compiler is best for python?

1 Answers  


Which is faster python or java?

1 Answers  


What are pandas in python?

1 Answers  


How to concatenate two lists in python?

1 Answers  


How does global value mutation used for thread-safety?

1 Answers  


What is the difference between re.search and re.match?

1 Answers  


Will python support object oriented?

1 Answers  


How will you differentiate between deep copy and shallow copy?

1 Answers  


What is super () react?

1 Answers  


How multithreading is achieved in python?

1 Answers  


Categories