Akansha Yadav shows how to use args and kwargs together in a single Python function. She writes a function that prints any arguments passed to it, then calls it four times with different combinations of positional and keyword arguments to demonstrate both work at the same time.
Chapters
Welcome back to my YouTube channel. In today's video, we will discuss about the functions two parameter, which is arg and kwargs. So basically, one is for the argument, another one is for the keyword arguments. So I am creating a function where I am going to call multiple times arg and then, uh, kwargs, and I'm just printing keyword, like whatever I have passed into the function. Nothing special I'm doing, I'm just creating a function and printing whatever values has been passed as a parameter to the function. So now I am calling my function, and when someone— I am calling my function, I am writing it first time, I am writing this first arg as a string, then I am writing 3 different arguments. Then when I am calling it third time, I am writing kwarg1 is equal to custom value, and I am changing it different, different times. Let's observe the output. So I have written the complete code, I have called my function 4 times. With a different number of inputs. So let's run the program and check out the output. So here you can see in the output that I am getting all the things in the output, like I am able to work with the argument and the keyword argument also at the same time in the same function. So if you wanted to use argument and keyword argument at the same time, so yes, you can work with this. You just have to pass it and you can call it accordingly. So if you like the video, don't forget to hit the like button and subscribe to the channel for more videos.