1 00:00:00,360 --> 00:00:05,190 In the previous videos, I showed you how to define a function with parameters. 2 00:00:05,550 --> 00:00:12,210 Now, the way I've shown you this and these parameters is what we call positional. 3 00:00:13,600 --> 00:00:21,520 Parameters or we might want to call them positional arguments, and they're called positional arguments 4 00:00:21,520 --> 00:00:24,430 because the position matters, right? 5 00:00:24,790 --> 00:00:35,650 If I change our arguments to, let's say, Andre, as the second argument and if I click or run, you 6 00:00:35,650 --> 00:00:41,710 see that I get Hello, Smiley face, Andre, which maybe is not what we want it to do. 7 00:00:42,190 --> 00:00:47,500 Positional arguments are arguments that require to be in the proper position. 8 00:00:47,680 --> 00:00:54,850 So if we defined name here first and then emoji second, you have to make sure that the first argument 9 00:00:54,880 --> 00:00:58,360 will be the name and the second argument will be the emoji. 10 00:01:00,480 --> 00:01:02,700 However, there's something called. 11 00:01:04,390 --> 00:01:06,640 Keyword arguments. 12 00:01:07,980 --> 00:01:15,270 And keyword arguments allow us to, well, not worry about the position, what do I mean, what I can 13 00:01:15,270 --> 00:01:19,500 do something like this, I can say, say hello. 14 00:01:20,160 --> 00:01:24,660 And in here, give it a key word, any value. 15 00:01:25,020 --> 00:01:31,290 So I'm going to say emoji equals to, let's say, the smiley face. 16 00:01:33,170 --> 00:01:38,180 And then Colma name equals to Bebe. 17 00:01:39,320 --> 00:01:40,670 Now, if I run this. 18 00:01:42,280 --> 00:01:45,160 You'll see that I get hello, Bebe. 19 00:01:46,940 --> 00:01:54,590 Because I was able to use keyword arguments, I tell it explicitly, hey, I want emoji to be this and 20 00:01:54,620 --> 00:01:56,450 name to be this. 21 00:01:57,370 --> 00:02:05,920 So positional arguments these matter, but keyword arguments it doesn't now I argue that this is bad 22 00:02:05,920 --> 00:02:11,160 practice because you're making the code more complicated than it needs to be. 23 00:02:11,860 --> 00:02:19,780 If the definition of the function is to give name an emoji, you should follow that practice and not 24 00:02:19,780 --> 00:02:21,130 confuse other developers. 25 00:02:21,340 --> 00:02:27,460 Then just stick to that name and emoji so you can still use keyword arguments. 26 00:02:27,610 --> 00:02:35,140 But make sure that they are in order, because why wouldn't you just follow what the function tells 27 00:02:35,140 --> 00:02:35,280 you? 28 00:02:36,100 --> 00:02:42,340 It's the same result, but at least this way you are following, well, the standard flow. 29 00:02:43,180 --> 00:02:51,730 And by the way, these keyword arguments can sometimes be confused with what we call default parameters. 30 00:02:52,660 --> 00:02:56,800 I know it can get really, really confusing, but this is something that will come naturally to you 31 00:02:56,800 --> 00:02:58,080 after you practice a little bit. 32 00:02:58,600 --> 00:03:03,910 So I'm going to just comment this out and show you how default parameters work. 33 00:03:05,200 --> 00:03:06,820 Default parameters. 34 00:03:07,940 --> 00:03:15,380 Allow us to give right in here as we're defining the function, what we want as default in this in our 35 00:03:15,380 --> 00:03:16,460 case, let's say. 36 00:03:17,770 --> 00:03:23,230 Darth Vader is the default name and the emoji will be. 37 00:03:25,150 --> 00:03:29,710 This little angry Darth Vader, well, it doesn't really look like Darth Vader. 38 00:03:30,620 --> 00:03:33,210 But this is the emoji that we are going to use. 39 00:03:33,920 --> 00:03:35,420 So what does this do? 40 00:03:36,170 --> 00:03:37,700 Well, if I run my program. 41 00:03:39,190 --> 00:03:43,930 Everything works the same if I do keyword arguments and run my program. 42 00:03:45,250 --> 00:03:46,180 Nothing changes. 43 00:03:47,050 --> 00:03:48,310 Let's make this a little bit bigger. 44 00:03:49,560 --> 00:03:57,120 However, default parameters allow us to do something interesting, for example, if I run. 45 00:03:58,050 --> 00:04:06,990 Another function, say hello, but I forget to give it parameters or arguments in our case. 46 00:04:07,500 --> 00:04:08,910 Well, if I run this. 47 00:04:11,560 --> 00:04:13,600 I get hello, Darth Vader. 48 00:04:14,860 --> 00:04:21,850 Because with default parameters, it says if you're not able to get name in emoji because you were called 49 00:04:21,850 --> 00:04:30,340 without any arguments, well, in that case, make default Darth Vader and may make default emoji. 50 00:04:30,670 --> 00:04:34,150 This little emoji, if I use let's say just. 51 00:04:36,410 --> 00:04:39,260 One argument and I click run. 52 00:04:40,610 --> 00:04:47,630 Then, well, it will fill that need variable, but anything that we don't give it, like emoji, will 53 00:04:47,630 --> 00:04:48,870 be pre defined. 54 00:04:49,220 --> 00:04:55,280 So this is a great way to make sure that your function runs, even if it's called the wrong way. 55 00:04:56,060 --> 00:05:03,590 So keyword arguments increases the readability of your code because you know exactly how we're calling. 56 00:05:03,610 --> 00:05:10,250 Say Hello and Dipple parameters allow us to keep our functions a little bit more safe because we make 57 00:05:10,250 --> 00:05:16,490 sure that when we use a variable, we're going to have a no matter what, regardless of how it is being 58 00:05:16,490 --> 00:05:16,820 called. 59 00:05:17,330 --> 00:05:22,060 But positional arguments are also useful because it's nice and clean. 60 00:05:22,070 --> 00:05:22,350 Right. 61 00:05:22,820 --> 00:05:27,430 We're just following what the function tells us to do and it's easy to read. 62 00:05:28,100 --> 00:05:30,560 So there's pros and cons of using each. 63 00:05:30,770 --> 00:05:38,120 But I hope this demonstrates to you some of the ways that you can define functions and also call functions 64 00:05:38,820 --> 00:05:39,710 I'll see in the next one.