1 00:00:00,750 --> 00:00:04,440 Let's talk about something called arguments and keyword arguments. 2 00:00:04,470 --> 00:00:07,050 I mean, we've already seen that before, right? 3 00:00:08,070 --> 00:00:15,030 With a function, we actually have this special characters that we can use called ARGs and Star Star 4 00:00:15,270 --> 00:00:17,100 Keyboard Parts. 5 00:00:18,520 --> 00:00:19,660 How can we use these? 6 00:00:21,320 --> 00:00:28,400 Well, let's have a look, let's try and have a function, let's say define and we'll call this a super 7 00:00:28,400 --> 00:00:28,730 funk. 8 00:00:30,110 --> 00:00:34,430 For super function that receives some sort of arguments. 9 00:00:35,630 --> 00:00:42,410 And these arguments that we're going to receive and remember, although I'm calling this ARGs, this 10 00:00:42,410 --> 00:00:44,450 itself is a parameter, remember? 11 00:00:44,870 --> 00:00:53,930 But let's say that we want to just return some of the arguments and you might be wondering where some 12 00:00:53,930 --> 00:00:59,080 don't we have to define that function of what some actually exists in Python, as you can see over here. 13 00:00:59,420 --> 00:01:02,300 So we can just return to some of the arguments. 14 00:01:03,050 --> 00:01:04,310 So let's try this. 15 00:01:04,550 --> 00:01:06,170 Let's say super func. 16 00:01:07,120 --> 00:01:12,550 And give it arguments, one, two, three, four or five, if I click, run. 17 00:01:15,850 --> 00:01:24,370 Hmm, I get in their super funk, takes one positional argument, but five where they give it and that 18 00:01:24,370 --> 00:01:25,100 makes sense, right? 19 00:01:25,120 --> 00:01:31,990 Like I only have one parameter here, which is a positional argument that it accepts. 20 00:01:32,200 --> 00:01:38,110 And I'm trying to sum this so it only receives one, but I'm giving it to all these things that it doesn't 21 00:01:38,110 --> 00:01:38,550 know about. 22 00:01:39,340 --> 00:01:46,360 And this is where we can use something like this by adding a star to here. 23 00:01:47,020 --> 00:01:53,950 We're saying, hey, this can accept any number of positional arguments like this. 24 00:01:54,890 --> 00:02:03,530 As many as I want, as a matter of fact, let's print this out, if I do print star arcs and we run 25 00:02:03,530 --> 00:02:04,130 this function. 26 00:02:05,950 --> 00:02:15,760 We see that the print starts gives us one, two, three, four, five, these are all the parameters 27 00:02:15,760 --> 00:02:17,140 or the arguments that we get. 28 00:02:17,450 --> 00:02:20,740 And if I actually remove the star here and click run. 29 00:02:22,360 --> 00:02:32,230 Look at that, I actually get this as a tuple so args inside of this function is a tuple of arguments 30 00:02:32,260 --> 00:02:34,520 that I give it one, two, three, four, five. 31 00:02:34,720 --> 00:02:40,140 So some of the tuple one, two, three, four, five is going to give us the right answer. 32 00:02:40,570 --> 00:02:42,880 It's going to print for us. 33 00:02:46,370 --> 00:02:48,050 The answer, Tuffin. 34 00:02:50,160 --> 00:02:53,490 Very, very cool, so this way we can extend. 35 00:02:54,500 --> 00:03:02,060 And use our Star ARGs to have a function that can accept any number of arguments. 36 00:03:03,330 --> 00:03:05,190 So what is this one now? 37 00:03:06,090 --> 00:03:07,230 Well, this one. 38 00:03:08,250 --> 00:03:16,770 Allows us to use keyword arguments, for example, let's say I have the star star keyboard arcs like 39 00:03:16,770 --> 00:03:20,730 this, and by the way, this can technically be anything. 40 00:03:20,760 --> 00:03:22,590 So this is a variable that we're creating. 41 00:03:22,590 --> 00:03:26,310 So I can name it who if I wanted to. 42 00:03:26,430 --> 00:03:34,530 But the standard is to name it ARGs and keyword arcs because other developers are using it this way 43 00:03:34,530 --> 00:03:36,750 and it's just the way it's done in the Python community. 44 00:03:37,750 --> 00:03:46,000 Now, with the key word, as you might have guessed, I can add keywords like number one equals. 45 00:03:46,990 --> 00:03:51,010 Five and then two equals 10. 46 00:03:52,590 --> 00:03:56,400 So that if I print the key word ARGs and I click run. 47 00:03:58,370 --> 00:04:06,680 I get a dictionary of numb one equals to five, and now I'm two equals to 10, so I can actually do 48 00:04:06,680 --> 00:04:15,320 something like some plus some of the items in the key word args. 49 00:04:16,320 --> 00:04:19,630 And grab the values, right? 50 00:04:19,680 --> 00:04:20,700 We've seen that before. 51 00:04:22,170 --> 00:04:32,580 And let's actually grab this and do a for loop and say items in keyword arcs, dot values, remember 52 00:04:32,580 --> 00:04:38,700 to grab the values over here and in here, just add up the totals. 53 00:04:38,850 --> 00:04:50,100 So let's say that in here, total equals or plus equals items and we'll add a total. 54 00:04:51,350 --> 00:04:56,930 And here, that is initially zero, so that some. 55 00:04:58,470 --> 00:05:01,770 Will be some ARC's plus total. 56 00:05:03,210 --> 00:05:04,110 If I run this. 57 00:05:09,670 --> 00:05:15,350 Which looks about right now, this does look a little confusing, so let's go over it. 58 00:05:15,970 --> 00:05:23,380 We have the Star ARGs which allow us to grab these positional arguments and just some everything. 59 00:05:23,740 --> 00:05:31,720 And we also have key word arcs which allow us to grab any number of keyword arguments and get a dictionary, 60 00:05:32,080 --> 00:05:36,220 which comes as key word arcs and then use them however we want. 61 00:05:36,220 --> 00:05:42,520 In our case, we're looping over all the values, so items and keyword are values and then I'm just 62 00:05:42,520 --> 00:05:44,620 going to total all those items. 63 00:05:46,100 --> 00:05:48,360 Have a total and just returned the some. 64 00:05:50,370 --> 00:05:57,090 Now, this is, again, extremely useful because our super fund can now take as many arguments, as 65 00:05:57,090 --> 00:06:00,540 many positional and keyword arguments as we want. 66 00:06:01,750 --> 00:06:09,430 Now, one final thing, there is a rule of the ordering that we can do all of our parameters here, 67 00:06:09,640 --> 00:06:10,010 right? 68 00:06:10,870 --> 00:06:16,540 So the order the rule is this first in our parameters. 69 00:06:17,880 --> 00:06:26,880 We have, well, our actual programs, then we can do star arcs, then default parameters. 70 00:06:27,990 --> 00:06:29,400 Then star star. 71 00:06:31,240 --> 00:06:32,560 Keyword parks. 72 00:06:35,480 --> 00:06:41,360 Let me show you what I mean, if we want to define dysfunction, we want to make sure that if we give 73 00:06:41,360 --> 00:06:44,150 it a parameter of, let's say name. 74 00:06:46,250 --> 00:06:54,380 That should come before Stathakis, and if we have default parameters, that should usually come after 75 00:06:54,410 --> 00:06:56,270 arcs but before key word arcs. 76 00:06:56,300 --> 00:07:03,230 So if I do, let's say I equals high and make sure we add a comma here. 77 00:07:04,490 --> 00:07:09,830 We now have following the rule, and by the way, you would never actually write a function like this 78 00:07:09,830 --> 00:07:12,900 because, well, frankly, it looks super confusing. 79 00:07:12,920 --> 00:07:18,370 Usually you're only using two of these or maybe just one of these. 80 00:07:19,040 --> 00:07:23,180 But this way I can call this function with name Andy. 81 00:07:24,570 --> 00:07:32,370 Then my arms, then my default parameter, which will be I equals to high, which let's say we don't 82 00:07:32,370 --> 00:07:34,860 even pass in, and then we have this. 83 00:07:36,650 --> 00:07:37,670 So if we run here. 84 00:07:39,080 --> 00:07:45,380 This still works, we are just not using name and I but you see that I'm following the rule of parents, 85 00:07:46,070 --> 00:07:49,340 ARC's default parameters and then keyword ARC's. 86 00:07:50,580 --> 00:07:53,290 All right, hopefully your head doesn't hurt too much after this one. 87 00:07:53,550 --> 00:07:55,310 Take a break and I'll see you in the next one.