Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,480 --> 00:00:05,610
In the previous videos I showed you how to define a function with parameters.
2
00:00:05,610 --> 00:00:15,980
Now the way I've shown you this and these parameters is what we call positional parameters or we might
3
00:00:15,980 --> 00:00:22,940
want to call them positional arguments and they're called positional arguments because the position
4
00:00:23,180 --> 00:00:24,830
matters right.
5
00:00:24,890 --> 00:00:36,080
If I change our arguments to let's say Andre as the second argument and if I click Run you see that
6
00:00:36,080 --> 00:00:44,990
I get Hello smiley face andre which maybe is not what we wanted to do positional arguments are arguments
7
00:00:44,990 --> 00:00:47,720
that require to be in the proper position.
8
00:00:47,750 --> 00:00:54,770
So if we defined name here first and then emoji Second you have to make sure that the first argument
9
00:00:54,920 --> 00:00:58,330
will be the name and the second argument will be the emotion.
10
00:01:00,550 --> 00:01:11,230
However there is something called key word arguments and keyword arguments allow us to.
11
00:01:11,230 --> 00:01:13,190
Well now worry about the position.
12
00:01:13,390 --> 00:01:14,260
What do I mean.
13
00:01:14,260 --> 00:01:17,050
Well I can do something like this.
14
00:01:17,140 --> 00:01:25,120
I can say say hello and in here give it a keyword and a value.
15
00:01:25,120 --> 00:01:39,370
So I'm going to say emoji equals to let's say the smiley face and then comma name equals to Bebe.
16
00:01:39,380 --> 00:01:43,390
Now if I run this you'll see that I get.
17
00:01:43,580 --> 00:01:49,710
Hello Bebe because I was able to use keyword arguments.
18
00:01:49,710 --> 00:01:59,290
I tell it explicitly hey I want the emoji to be this and name to be this so positional arguments these
19
00:01:59,290 --> 00:02:01,610
matter but keyword arguments.
20
00:02:01,750 --> 00:02:03,160
It doesn't.
21
00:02:03,160 --> 00:02:10,780
Now I argue that this is bad practice because you're making the code more complicated than it needs
22
00:02:10,780 --> 00:02:11,950
to be.
23
00:02:11,950 --> 00:02:20,260
If the definition of the function is to give name an emoji you should follow that practice and not confuse
24
00:02:20,290 --> 00:02:28,360
other developers then just stick to that name and emoji so you can still use keyword arguments but make
25
00:02:28,360 --> 00:02:36,020
sure that they are in order because why wouldn't you just follow what the function tells you.
26
00:02:36,190 --> 00:02:44,530
It's the same result but at least this way you are following Well the standard flow and by the way these
27
00:02:44,530 --> 00:02:52,560
keyword arguments can sometimes be confused we what we call default parameters.
28
00:02:52,750 --> 00:02:57,130
I know it can get really really confusing but this is something that will come naturally to you after
29
00:02:57,130 --> 00:02:58,660
you practice a little bit.
30
00:02:58,660 --> 00:03:06,830
So I'm going to just comment this out and show you how default parameters work default parameters.
31
00:03:08,050 --> 00:03:15,100
Allow us to give right in here as we're defining the function what we want as default in this.
32
00:03:15,100 --> 00:03:27,300
In our case let's say Darth Vader is the default name and the IMO g will be this little angry Darth
33
00:03:27,300 --> 00:03:27,900
Vader.
34
00:03:28,020 --> 00:03:34,010
While it doesn't really look like Darth Vader but this is the emoji that we gonna use.
35
00:03:34,010 --> 00:03:36,260
So what does this do.
36
00:03:36,260 --> 00:03:40,790
Well if I run my program everything works the same.
37
00:03:40,930 --> 00:03:47,010
If I do keyword arguments and run my program nothing changes.
38
00:03:47,150 --> 00:03:48,290
Let's make this a little bit bigger.
39
00:03:49,640 --> 00:03:55,290
However default parameters allow us to do something interesting.
40
00:03:55,310 --> 00:04:06,540
For example if I run a another function say hello but I forget to give it parameters or arguments in
41
00:04:06,540 --> 00:04:07,500
our case.
42
00:04:07,560 --> 00:04:12,090
Well if I run this I get.
43
00:04:12,120 --> 00:04:12,930
Hello.
44
00:04:12,930 --> 00:04:20,770
Darth Vader because with default parameters it says if you're not able to get name and emoji because
45
00:04:20,920 --> 00:04:24,610
you are called without any arguments.
46
00:04:24,760 --> 00:04:30,640
Well in that case make default Darth Vader and make default emoji.
47
00:04:30,760 --> 00:04:44,490
This little emoji if I use lets say just one argument and I click run then well it will fill that need
48
00:04:44,490 --> 00:04:48,870
variable but anything that we don't give it like emoji will be pre defined.
49
00:04:49,290 --> 00:04:56,030
So this is a great way to make sure that your function runs even if it's called the wrong way.
50
00:04:56,100 --> 00:05:03,600
So keyword arguments increases the readability of your code because you know exactly how we're calling
51
00:05:03,600 --> 00:05:10,530
say hello and DFL parameters allow us to keep our functions a little bit more safe because we make sure
52
00:05:10,530 --> 00:05:17,550
that when we use a variable we're gonna have no matter what regardless of how it is being called but
53
00:05:17,550 --> 00:05:22,840
positional arguments are also useful because it's nice and clean right.
54
00:05:22,890 --> 00:05:26,060
We're just following what the function tells us to do.
55
00:05:26,340 --> 00:05:27,940
And it's easy to read.
56
00:05:28,170 --> 00:05:34,260
So there's pros and cons of using each but I hope this demonstrates to you some of the ways that you
57
00:05:34,260 --> 00:05:38,910
can define functions and also call functions.
58
00:05:38,910 --> 00:05:40,120
I'll see in the next one.
59
00:05:40,250 --> 00:05:40,430
Bob.
6127
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.