1 00:00:00,000 --> 00:00:01,000 [no audio] 2 00:00:01,000 --> 00:00:02,300 Friends here we are discussing 3 00:00:02,300 --> 00:00:05,200 about functions with variable length arguments. 4 00:00:06,000 --> 00:00:09,900 So what is meant by variable-length arguments? See, 5 00:00:09,900 --> 00:00:13,000 we know that whenever we define a function, right, 6 00:00:13,400 --> 00:00:17,100 so it may take either one argument, or two arguments, or three, 7 00:00:17,800 --> 00:00:19,400 and based on that we are passing. 8 00:00:19,800 --> 00:00:23,100 Let me open a simple script for that. 9 00:00:24,100 --> 00:00:29,600 Suppose if I define a function 'display', so I want to define 10 00:00:29,600 --> 00:00:33,200 a function just to find out the type of your passed variable. 11 00:00:33,200 --> 00:00:36,200 [no audio] 12 00:00:36,200 --> 00:00:38,100 That's it. Right. Now, 13 00:00:38,100 --> 00:00:39,400 I am calling, suppose. 14 00:00:40,900 --> 00:00:41,600 It's working. 15 00:00:42,000 --> 00:00:45,800 So how many arguments your function is taking? Only one argument, 16 00:00:45,900 --> 00:00:48,000 right. In case if I pass 17 00:00:48,000 --> 00:00:49,900 [no audio] 18 00:00:49,900 --> 00:00:54,300 two arguments, it won't accept because it is taking only one 19 00:00:54,300 --> 00:00:57,700 argument, but we are passing two. Right. 20 00:00:58,000 --> 00:01:01,500 So even though if you pass two arguments suppose if your 21 00:01:01,500 --> 00:01:06,000 function is ready to accept then that is called a variable 22 00:01:06,200 --> 00:01:12,300 length argument function, means number of arguments, whatever 23 00:01:12,300 --> 00:01:15,200 the arguments you are passing, right, the number of arguments 24 00:01:15,200 --> 00:01:19,500 if they vary then that is called variable length arguments 25 00:01:19,500 --> 00:01:20,600 for your functions. 26 00:01:21,900 --> 00:01:24,900 Generally, it won't accept, right. See if I pass 4, 27 00:01:24,900 --> 00:01:26,900 5, now two variables 28 00:01:26,900 --> 00:01:28,200 we are passing. Now 29 00:01:28,200 --> 00:01:30,100 your function is not ready to accept that. 30 00:01:31,800 --> 00:01:37,500 Right. But we have a small syntax for your function to define 31 00:01:37,800 --> 00:01:42,100 such that it is ready to take any number of arguments, 32 00:01:42,600 --> 00:01:49,800 right? Let me define it now. Suppose 'display(*data)'. 33 00:01:50,500 --> 00:01:55,100 Generally, if you Google it, you can see the syntax as 'arg', 34 00:01:55,100 --> 00:01:57,100 argument, '*arg'. 35 00:01:57,600 --> 00:01:59,200 So that is not a standard variable. 36 00:01:59,400 --> 00:02:02,200 You can take any variable because they are arguments 37 00:02:02,200 --> 00:02:03,600 whatever the value we are writing here 38 00:02:03,600 --> 00:02:04,800 they are generally arguments, right, 39 00:02:04,800 --> 00:02:07,900 that's why they are taking 'arg'. Not only that you can take 40 00:02:07,900 --> 00:02:09,100 simply 'data' also. 41 00:02:10,400 --> 00:02:12,300 Right. Then first 42 00:02:12,300 --> 00:02:16,900 let me print what you are getting if we take variable length arguments, 43 00:02:18,300 --> 00:02:20,900 what is the, what type of data you are getting whenever if you 44 00:02:20,900 --> 00:02:25,100 pass your data to your 'display' function. So to know that 45 00:02:25,200 --> 00:02:26,700 I am printing simply your 'data'. 46 00:02:27,100 --> 00:02:28,500 Now, let me call your function. 47 00:02:29,700 --> 00:02:33,600 I am calling without any 'data', without passing any arguments, 48 00:02:34,300 --> 00:02:35,700 zero arguments I am passing. 49 00:02:35,700 --> 00:02:38,600 Now, your function is ready to accept. And observe 50 00:02:38,600 --> 00:02:40,000 the 'data' what you are passing. 51 00:02:41,100 --> 00:02:46,200 Tuple, empty tuple. Now, let me call it with one argument. 52 00:02:47,200 --> 00:02:50,300 Yes, again it is ready to accept one argument as a tuple. 53 00:02:51,100 --> 00:02:54,300 Now, let me call it with some number of values. 54 00:02:55,100 --> 00:02:58,400 Yes, again it is ready to accept. That means see, number of 55 00:02:58,400 --> 00:02:59,500 arguments are varied, right. 56 00:02:59,600 --> 00:03:02,700 This is nothing but variable length arguments. Even though 57 00:03:02,700 --> 00:03:06,600 if you change number of arguments, even though if you pass 58 00:03:07,600 --> 00:03:11,400 number of arguments, each time different number of arguments, 59 00:03:11,600 --> 00:03:15,900 your function is ready to accept that, right. Now to accept that, 60 00:03:15,900 --> 00:03:20,300 nothing is there. Simply write '*', generally '*' means zero or more. 61 00:03:20,600 --> 00:03:24,500 You can pass zero arguments or more number of arguments - 0, 62 00:03:24,600 --> 00:03:28,000 1, or 2, or 3, or 4, any number of arguments you can pass to 63 00:03:28,000 --> 00:03:33,800 your function whenever if you define your parameters as '*', 64 00:03:33,900 --> 00:03:39,400 some variable. Not only 'data' guys, generally 'arg'. 65 00:03:39,400 --> 00:03:43,100 [no audio] 66 00:03:43,100 --> 00:03:50,400 That's it. Now let me comment. Let me comment these two functions, 67 00:03:50,400 --> 00:03:52,600 I mean fourth line and fifth Line. 68 00:03:52,600 --> 00:03:55,200 [no audio] 69 00:03:55,200 --> 00:03:57,700 See, we know if it is a tuple, right, 70 00:03:57,700 --> 00:04:00,800 we can take one by one argument from that, one by one value 71 00:04:00,800 --> 00:04:06,100 from that using loop, for loop, 'for each in your arg'. Guys be 72 00:04:06,100 --> 00:04:08,000 clear, 'arg' is not a fixed variable, 73 00:04:08,000 --> 00:04:10,500 you can take anything. The only thing, whatever the data you 74 00:04:10,500 --> 00:04:14,400 are passing, whatever the arguments you are passing, all arguments 75 00:04:14,400 --> 00:04:17,899 stored into this variable as a tuple. If it is a tuple 76 00:04:17,899 --> 00:04:20,700 I can take one by one value from that, right? 77 00:04:20,700 --> 00:04:21,800 That's what I am doing here. 78 00:04:23,100 --> 00:04:24,700 Now, let me run it and see the result. 79 00:04:24,700 --> 00:04:26,600 [no audio] 80 00:04:26,600 --> 00:04:30,700 Right. Now just for your understanding, just I am calling once again 81 00:04:30,700 --> 00:04:31,800 with different values. 82 00:04:33,200 --> 00:04:34,300 'display()' function, 83 00:04:34,300 --> 00:04:39,400 let me take simply "Hi", and then suppose some 4.6, whatever 84 00:04:39,400 --> 00:04:41,100 it may be data. See that. It's working. 85 00:04:41,700 --> 00:04:44,200 So whether you are passing three arguments or two arguments, 86 00:04:44,200 --> 00:04:47,200 now your function is ready to accept, right? 87 00:04:47,200 --> 00:04:50,500 So this is nothing but simply variable length arguments in 88 00:04:50,500 --> 00:04:52,700 your functions, okay. 89 00:04:53,600 --> 00:04:55,700 Okay guys, thank you for watching this video. 90 00:04:55,700 --> 00:05:02,336 [no audio]