Args and kwrags

How to unpack args and kwargs?

Hello @merajzafir, args represents the tuple values or the non-keyword arguments and kwargs represents the keyword arguments. So python generally follows a pattern just pass all the required parameters first then pass all the args and then at the last pass the kwargs. So after this first of all it will try to unpack values of all the required parameters, and then all the left out non-keyword arguments will be considered as args and if there is not any then we will get an empty tuple, and then if we have some keyword arguments then we can pass that as well and that will become the part of the kwargs. I hope it is clear to you, and if still there is anything that is not clear to you, pls let me know.
Thanks :slight_smile:

suppose we don’t have parameters other than *args and **kwargs, then how can we unpack them into a separate variable inside the function

okay it doesn’t matter if we have additional parameters in case we have python understood the first one’s in the list are args and if there aren’t any they will check for the kwargs and similarly if we don’t get anything in kwargs it won’t take anything.