1 00:00:00,360 --> 00:00:01,859 -: In the previous videos, 2 00:00:01,859 --> 00:00:05,580 I showed you how to define a function with parameters. 3 00:00:05,580 --> 00:00:09,630 Now, the way I've shown you this, and these parameters, 4 00:00:09,630 --> 00:00:14,520 is what we call positional parameters. 5 00:00:14,520 --> 00:00:19,500 Or, we might want to call them positional arguments. 6 00:00:19,500 --> 00:00:21,510 And they're called positional arguments 7 00:00:21,510 --> 00:00:24,810 because the position matters, right? 8 00:00:24,810 --> 00:00:29,500 If I change our arguments to, let's say, Andrei 9 00:00:30,930 --> 00:00:35,460 as the second argument, and if I click run, 10 00:00:35,460 --> 00:00:39,270 you see that I get, hello, smiley face, Andrei. 11 00:00:39,270 --> 00:00:42,210 Which maybe is not what we want it to do. 12 00:00:42,210 --> 00:00:46,290 Positional arguments are arguments that require to be 13 00:00:46,290 --> 00:00:47,670 in the proper position. 14 00:00:47,670 --> 00:00:52,620 So, if we defined name here first and then emoji second, 15 00:00:52,620 --> 00:00:54,870 you have to make sure that the first argument 16 00:00:54,870 --> 00:00:58,473 will be the name, and the second argument will be the emoji. 17 00:01:00,480 --> 00:01:02,770 However, there's something called 18 00:01:04,319 --> 00:01:06,813 keyword arguments. 19 00:01:08,010 --> 00:01:11,190 And keyword arguments allow us to, 20 00:01:11,190 --> 00:01:13,320 well, not worry about the position. 21 00:01:13,320 --> 00:01:14,250 What do I mean? 22 00:01:14,250 --> 00:01:17,100 Well, I can do something like this. 23 00:01:17,100 --> 00:01:20,160 I can say, say hello, 24 00:01:20,160 --> 00:01:25,050 and in here give it a keyword and a value. 25 00:01:25,050 --> 00:01:29,490 So I'm going to say emoji equals to 26 00:01:29,490 --> 00:01:31,443 let's say this smiley face. 27 00:01:33,210 --> 00:01:38,210 And then comma name equals to Bibi. 28 00:01:39,330 --> 00:01:40,863 Now, if I run this, 29 00:01:42,300 --> 00:01:45,303 you'll see that I get, hello Bibi. 30 00:01:46,950 --> 00:01:49,650 Because I was able to use keyword arguments, 31 00:01:49,650 --> 00:01:52,590 I tell it explicitly, hey, 32 00:01:52,590 --> 00:01:57,390 I want emoji to be this and name to be this. 33 00:01:57,390 --> 00:01:59,760 So positional arguments, these matter. 34 00:01:59,760 --> 00:02:03,120 But keyword arguments, it doesn't. 35 00:02:03,120 --> 00:02:07,140 Now, I argue that this is bad practice. 36 00:02:07,140 --> 00:02:10,289 Because you're making the code more complicated 37 00:02:10,289 --> 00:02:11,880 than it needs to be. 38 00:02:11,880 --> 00:02:16,880 If the definition of the function is to give name and emoji, 39 00:02:17,610 --> 00:02:19,380 you should follow that practice 40 00:02:19,380 --> 00:02:21,330 and not confuse other developers. 41 00:02:21,330 --> 00:02:25,140 Then just stick to that name and emoji. 42 00:02:25,140 --> 00:02:27,630 So you can still use keyword arguments, 43 00:02:27,630 --> 00:02:32,010 but make sure that they are in order, because why 44 00:02:32,010 --> 00:02:36,120 wouldn't you just follow what the function tells you? 45 00:02:36,120 --> 00:02:39,270 It's the same result, but at least this way 46 00:02:39,270 --> 00:02:43,230 you are following, well, the standard flow. 47 00:02:43,230 --> 00:02:44,220 And, by the way, 48 00:02:44,220 --> 00:02:47,790 these keyword arguments can sometimes be confused 49 00:02:47,790 --> 00:02:51,873 with what we call default parameters. 50 00:02:52,710 --> 00:02:54,510 I know, it can get really, really confusing, 51 00:02:54,510 --> 00:02:56,790 but this is something that will come naturally to you 52 00:02:56,790 --> 00:02:58,590 after you practice a little bit. 53 00:02:58,590 --> 00:03:01,350 So, I'm going to just comment this out, 54 00:03:01,350 --> 00:03:04,023 and show you how default parameters work. 55 00:03:05,160 --> 00:03:10,160 Default parameters allow us to give right in here, 56 00:03:10,740 --> 00:03:12,900 as we're defining the function, 57 00:03:12,900 --> 00:03:14,610 what we want as default. 58 00:03:14,610 --> 00:03:19,110 In this, in our case, let's say Darth Vader 59 00:03:19,110 --> 00:03:23,320 is the default name, and the emoji will be 60 00:03:25,140 --> 00:03:27,990 this little angry Darth Vader. 61 00:03:27,990 --> 00:03:30,660 Well, it doesn't really look like Darth Vader. 62 00:03:30,660 --> 00:03:33,960 But. this is the emoji that we are gonna use. 63 00:03:33,960 --> 00:03:36,180 So, what does this do? 64 00:03:36,180 --> 00:03:40,860 Well, if I run my program, everything works the same. 65 00:03:40,860 --> 00:03:44,073 If I do keyword arguments and run my program, 66 00:03:45,240 --> 00:03:47,100 nothing changes. 67 00:03:47,100 --> 00:03:49,560 Let's make this a little bit bigger. 68 00:03:49,560 --> 00:03:53,580 However, default parameters allow us 69 00:03:53,580 --> 00:03:55,260 to do something interesting. 70 00:03:55,260 --> 00:04:00,090 For example, if I run another function, 71 00:04:00,090 --> 00:04:01,500 say hello, 72 00:04:01,500 --> 00:04:06,500 but I forget to give it parameters or arguments in our case. 73 00:04:07,500 --> 00:04:09,093 Well, if I run this, 74 00:04:11,610 --> 00:04:13,713 I get, hello Darth Vader. 75 00:04:14,880 --> 00:04:16,800 Because with default parameters, 76 00:04:16,800 --> 00:04:20,310 It says if you're not able to get name and emoji 77 00:04:20,310 --> 00:04:24,690 because you are called without any arguments, 78 00:04:24,690 --> 00:04:28,020 well in that case, make default Darth Vader, 79 00:04:28,020 --> 00:04:32,280 and maybe make default emoji this little emoji. 80 00:04:32,280 --> 00:04:33,570 If I use, let's say, 81 00:04:33,570 --> 00:04:38,340 just one argument, 82 00:04:38,340 --> 00:04:39,393 and I click run, 83 00:04:40,590 --> 00:04:45,180 then, well, it will fill that name variable. 84 00:04:45,180 --> 00:04:46,620 But anything that we don't give it, 85 00:04:46,620 --> 00:04:49,230 like emoji, will be pre-defined. 86 00:04:49,230 --> 00:04:53,700 So, this is a great way to make sure that your function runs 87 00:04:53,700 --> 00:04:56,070 even if it's called the wrong way. 88 00:04:56,070 --> 00:05:01,070 So, keyword arguments increases the readability of your code 89 00:05:01,200 --> 00:05:04,560 because you know exactly how we're calling say, hello. 90 00:05:04,560 --> 00:05:08,070 And default parameters allow us to keep our functions 91 00:05:08,070 --> 00:05:11,010 a little bit more safe because we make sure that 92 00:05:11,010 --> 00:05:14,070 when we use a variable, we're gonna have it no matter what. 93 00:05:14,070 --> 00:05:17,370 Regardless of how it is being called. 94 00:05:17,370 --> 00:05:19,920 But, positional arguments are also useful 95 00:05:19,920 --> 00:05:22,830 because it's nice and clean, right? 96 00:05:22,830 --> 00:05:26,280 We're just following what the function tells us to do, 97 00:05:26,280 --> 00:05:28,110 and it's easy to read. 98 00:05:28,110 --> 00:05:30,840 So there's pros and cons of using each. 99 00:05:30,840 --> 00:05:33,960 But I hope this demonstrates to you some of the ways 100 00:05:33,960 --> 00:05:38,850 that you can define functions, and also call functions. 101 00:05:38,850 --> 00:05:40,800 I'll see you in the next one, bye, bye.