Decorators related doubt

In the wrapper function, we have mentioned kwargs as an argument, is it required to be used every time? As it seems that it is not required here?

I didn’t understand the topic as well as the code, can anyone explain it to me

Decorator is basically used when we are not changing our original function but we are still able to add extra features to it. Like sir explained in the tutorial, we have not made changes to the sum function but we have made sure that the sum function works only if the user enters correct name and password.

Hello @yashikakhurana00,

**kwargs are used for keyword arguments, so its upto the you to decide how to call the function in this scenerio, i.e whether you want to call add as :

add("user1", "pass123",  a=1, b=2)

or

add("user1", "pass123", 1, 2)

In the first case, you needed the **kwargs, but in the second, there is not necessity. So, yes its not neccesary to pass kwargs every time when we are making our own code. But sometimes, you might want to pass keyword arguments, as it is the case with most of library functions out there.

Also, its a good practice to do *args, **kwargs whenever you are manipulating a function behaviour.

Thanks :slightly_smiling_face:

1 Like

great. thanks for the answer!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.