1
00:00:01,520 --> 00:00:08,180
Some functions in Python such as the len function get only one argument.

2
00:00:08,180 --> 00:00:17,090
If you tried to pass more than one it will return an error saying that it takes exactly one argument.

3
00:00:17,090 --> 00:00:26,210
Some other functions such as isinstance take exactly two arguments.

4
00:00:26,460 --> 00:00:33,340
So if you try to pass three arguments, or just one

5
00:00:33,500 --> 00:00:35,250
you will get an error.

6
00:00:35,300 --> 00:00:37,460
Some other functions such as print

7
00:00:40,850 --> 00:00:49,730
take an indefinite number of arguments and you sow how we can define such functions with only one or more

8
00:00:49,850 --> 00:00:54,790
arguments but I haven't still explained how to create these kinds of functions.

9
00:00:54,830 --> 00:00:58,940
Let's create one. Define let's call this mean.

10
00:00:58,970 --> 00:01:02,370
So to calculate the mean of the series of numbers.

11
00:01:02,390 --> 00:01:04,130
So imagine this.

12
00:01:04,130 --> 00:01:09,030
This was our function we want to pass as many items as we want.

13
00:01:09,140 --> 00:01:16,400
We actually did create a min function earlier which we could call like that but it still got only

14
00:01:16,400 --> 00:01:20,120
one argument so it was a list like that.

15
00:01:20,210 --> 00:01:24,220
It's still one object, one argument.
In this case we don't want to pass a list there.

16
00:01:24,230 --> 00:01:33,960
We want to pass as many items as we want so mean and then what do you use the asterisk and then args.

17
00:01:35,780 --> 00:01:40,560
This can be anything actually after the asterisk, any variable name would work.

18
00:01:40,670 --> 00:01:47,870
But it's a good practice because every programmer uses args so it's good that you use args so others can

19
00:01:47,870 --> 00:01:53,200
read your code and you also get used to reading others code by using args all the time.

20
00:01:53,270 --> 00:01:57,360
You know what the others are talking about.

21
00:01:57,560 --> 00:02:05,840
Now let me show you something before I apply the algorithm that calculates the mean, return args.

22
00:02:06,410 --> 00:02:08,410
Let's see what we get here.

23
00:02:08,540 --> 00:02:11,970
Let me call the function.

24
00:02:12,460 --> 00:02:13,810
So 1 3.

25
00:02:13,920 --> 00:02:17,490
You can also pass string whatever you like like that.

26
00:02:20,390 --> 00:02:28,560
And what you get is actually a tuple containing all the items, all the objects that you pass in the

27
00:02:28,560 --> 00:02:29,910
function call.

28
00:02:29,970 --> 00:02:31,080
So that actually

29
00:02:33,750 --> 00:02:39,350
is a tuple.

30
00:02:39,370 --> 00:02:44,820
So what can we do with that tuple? Well, we can calculate the sum of args.

31
00:02:44,860 --> 00:02:55,120
So args is a variable not asterisk args divided by the length of args.

32
00:02:55,240 --> 00:03:02,920
In this case we would gets an error because we have a there so remove a from there and try again, a string

33
00:03:02,950 --> 00:03:07,440
so it does make sense to have the average of a string.

34
00:03:07,570 --> 00:03:15,550
So we just created a function with an arbitrary number of non keyword arguments only. I say only because

35
00:03:16,060 --> 00:03:20,310
you cannot have keyword arguments here.

36
00:03:20,380 --> 00:03:28,590
You see X equal to 3 would not work here.
If you want keyword arguments then see the next video.

