1 00:00:00,000 --> 00:00:01,610 [No audio] 2 00:00:01,611 --> 00:00:03,732 Some functions in Python, such as the 3 00:00:03,733 --> 00:00:08,106 len function, get only one argument. 4 00:00:08,107 --> 00:00:12,932 If you try to pass more than one, it will 5 00:00:12,933 --> 00:00:17,018 return an error, saying that it takes exactly one argument. 6 00:00:17,019 --> 00:00:22,370 Some other functions, such as isinstance, 7 00:00:22,371 --> 00:00:26,812 take exactly 2 arguments, 2. 8 00:00:26,813 --> 00:00:31,356 If you try to pass 3 arguments, or 9 00:00:31,357 --> 00:00:35,130 just 1, you will get an error. 10 00:00:35,131 --> 00:00:37,563 Some other functions, such as print, 11 00:00:37,564 --> 00:00:40,700 [No audio] 12 00:00:40,701 --> 00:00:42,192 take an indefinite 13 00:00:42,193 --> 00:00:45,162 number of arguments and you saw how we can 14 00:00:45,163 --> 00:00:50,848 define such functions with only one or more argument. 15 00:00:50,849 --> 00:00:52,542 But I haven't still explained how 16 00:00:52,543 --> 00:00:54,772 to create these kinds of functions. 17 00:00:54,773 --> 00:00:58,894 Let's create one define, let's call this mean. 18 00:00:58,895 --> 00:01:02,222 So to calculate the mean of a series of numbers. 19 00:01:02,223 --> 00:01:05,090 So imagine this was our function. 20 00:01:05,091 --> 00:01:08,960 We want to pass as many items as we want. 21 00:01:08,961 --> 00:01:11,618 We actually did create a mean function 22 00:01:11,619 --> 00:01:14,642 earlier, which we could call like that, 23 00:01:14,643 --> 00:01:17,016 but it still got only one argument. 24 00:01:17,017 --> 00:01:19,940 So it was a list, like that. 25 00:01:19,941 --> 00:01:22,284 It's still one object, one argument. 26 00:01:22,285 --> 00:01:24,278 In this case, we don't want to pass a list there. 27 00:01:24,279 --> 00:01:27,570 We want to pass as many items as we want. 28 00:01:28,520 --> 00:01:30,682 So mean, and then what you do, 29 00:01:30,683 --> 00:01:34,180 you use the asterisk and then args. 30 00:01:35,560 --> 00:01:38,986 This can be anything actually, after the Asterisk, any 31 00:01:38,987 --> 00:01:40,538 variable name would work. 32 00:01:40,539 --> 00:01:41,872 But it's a good practice 33 00:01:41,873 --> 00:01:44,160 because every programmer uses args. 34 00:01:44,161 --> 00:01:46,628 So it's good that you use args 35 00:01:46,629 --> 00:01:48,606 so others can read your code. 36 00:01:48,607 --> 00:01:50,670 And you also get used to reading others 37 00:01:50,671 --> 00:01:53,150 code by using args all the time. 38 00:01:53,151 --> 00:01:55,950 You know what the others are talking about. 39 00:01:57,280 --> 00:01:59,410 Now let me show you something before I 40 00:01:59,411 --> 00:02:02,279 apply the algorithm that calculates the mean. 41 00:02:02,280 --> 00:02:04,300 [Author typing] 42 00:02:04,301 --> 00:02:08,374 return args, let's see what we get here. 43 00:02:08,375 --> 00:02:09,729 Now, let me call the function. 44 00:02:09,730 --> 00:02:12,266 [Author typing] 45 00:02:12,266 --> 00:02:15,062 So 1, 3, you can also pass 46 00:02:15,063 --> 00:02:17,810 strings to whatever you like, like that. 47 00:02:17,811 --> 00:02:20,133 [Author typing] 48 00:02:20,133 --> 00:02:23,552 And what you get is actually a tuple 49 00:02:23,553 --> 00:02:27,322 containing all the items, all the objects that 50 00:02:27,323 --> 00:02:29,818 you passed in the function call. 51 00:02:29,819 --> 00:02:31,317 So that actually 52 00:02:31,318 --> 00:02:33,533 [Author typing] 53 00:02:33,534 --> 00:02:35,233 is a tuple. 54 00:02:35,234 --> 00:02:39,133 [No audio] 55 00:02:39,133 --> 00:02:41,218 So what can we do with that tuple? 56 00:02:41,219 --> 00:02:44,770 Well we can calculate the sum of args. 57 00:02:44,771 --> 00:02:50,390 So args is a variable, not asterisk args 58 00:02:50,391 --> 00:02:53,450 divided by the length of the args. 59 00:02:54,910 --> 00:02:56,528 In this case, we would get an 60 00:02:56,529 --> 00:02:58,352 error because we have a there. 61 00:02:58,353 --> 00:03:01,908 So remove a from there and try again. 62 00:03:01,909 --> 00:03:03,732 a is a string, so it doesn't make 63 00:03:03,733 --> 00:03:07,330 sense to have the average of a string. 64 00:03:07,331 --> 00:03:09,652 So we just created a function with 65 00:03:09,653 --> 00:03:13,674 an arbitrary number of known keyword arguments 66 00:03:13,675 --> 00:03:16,148 only. I say only because you 67 00:03:16,149 --> 00:03:18,480 cannot have keyword arguments here. 68 00:03:20,130 --> 00:03:24,600 You see, x equal to 3 would not work here. 69 00:03:25,210 --> 00:03:28,920 If you want keyword arguments, then see the next video. 70 00:03:28,921 --> 00:03:32,200 [Outro sound]