Akansha Yadav shows how Python's args lets functions accept any number of positional arguments. She defines a function that iterates over args and calls it with three integers, two strings, no arguments, and a mix of types, demonstrating its flexibility across different data types.
Chapters
Hello everyone, welcome back to my YouTube channel. In today's video, we will discuss about the very important thing in the functions. So basically, that is args. Args is basically one of the parameter that you can pass on to the function. It's basically a short form of argument. So if you are not sure how many arguments you are going to pass on to the function or you are going to use within the function, then you can use this asterisk symbol args. So this will let you to pass multiple arguments. It's not going to be the fix. So here I have created a function, then writing a for loop, following up. Now I'm going to call my function. So first I am calling my function with the 3 numbers, 1, 2, 3. Then I am calling my function with 2 words, hello world. Then I am calling my function with nothing, it means I am not passing anything. In that case, we will be getting no output as well. Then I am going to call my function with the different data types. So I'm writing 1, hello, and then creating a list as well. So in this case, what will happen? We will— it will work for each and everything. It means when I have called this function 4 times, so it will work all 4 times because I am using asterisk symbol, arg, and this lets us to call it with a number of variables. So I have run this program. Let's check out the output. So here you can see I am getting 1, 2, 3, which was the output of the first one, then hello world, then I am getting 1, hello, 3, 4, 5. It means number, string, and a list. So this is how we used argument in a function. So if you like the video, don't forget to hit the subscribe button and like, comment,