1
00:00:00,580 --> 00:00:03,640
Hello and welcome to this video.

2
00:00:03,730 --> 00:00:08,270
What is a default parameter valid.

3
00:00:08,350 --> 00:00:14,250
This is the value that a function uses when it is called.

4
00:00:14,320 --> 00:00:17,440
Without passing it a value.

5
00:00:17,950 --> 00:00:29,140
So when you call a function without a parameter it uses the default value only parameters at the end

6
00:00:29,260 --> 00:00:35,200
of a parameter list can have a default value.

7
00:00:35,200 --> 00:00:43,700
This is because the values are assigned by the position.

8
00:00:43,720 --> 00:00:53,770
So if you have several parameters you can only give the last parameter in the list a default value in

9
00:00:53,770 --> 00:00:55,990
the first example here.

10
00:00:55,990 --> 00:01:07,360
Now this is a proper way of assigning a default parameter value because this has two parameter parameter

11
00:01:07,390 --> 00:01:13,540
a impairment to be because of the way the values are assigned by the position.

12
00:01:13,540 --> 00:01:22,090
You can only give a default parameter value to the last Parliament inside the function definition.

13
00:01:22,090 --> 00:01:24,050
So this is the proper way.

14
00:01:24,630 --> 00:01:31,600
And this one is not the right way because you see him giving it a default value here when he should

15
00:01:31,600 --> 00:01:35,420
be at the end of the parameter list.

16
00:01:35,510 --> 00:01:37,500
Let's create a new function.

17
00:01:37,540 --> 00:01:50,320
So I'm going to create a function called student on the score names and inside the parenthesis I'm going

18
00:01:50,320 --> 00:01:55,330
to define just one default value.

19
00:01:55,570 --> 00:02:02,320
So I'm going to call it names names is going gonna be the parameter.

20
00:02:02,320 --> 00:02:08,100
I'm going to use the equals to sign to assign a value to the parameter.

21
00:02:08,170 --> 00:02:16,090
I'm going to call it blue line so that is the parameter names.

22
00:02:16,090 --> 00:02:18,390
And this is the default value.

23
00:02:18,590 --> 00:02:25,160
So I had my colon and tab and I'll start a new line of code.

24
00:02:25,850 --> 00:02:35,900
So inside my function body I want to add a print function inside that print function.

25
00:02:35,900 --> 00:02:44,500
I want the print function to say hello plus the student's name.

26
00:02:44,840 --> 00:02:45,630
So I.

27
00:02:45,710 --> 00:02:57,230
Which is to a space and add a addition operator and then add the name of my parameter.

28
00:02:57,230 --> 00:02:59,780
So my parameter here is called names.

29
00:02:59,780 --> 00:03:05,380
So what I'm saying once I run this code any values are passed to it.

30
00:03:05,420 --> 00:03:12,470
It will print out Hello plus whatever name I passed to the function.

31
00:03:12,470 --> 00:03:19,640
So let's try and call the function and pass it some arguments to call the function you call the function

32
00:03:20,300 --> 00:03:31,970
by its name which is call student on the score names and then inside the parentheses I can pass in different

33
00:03:31,970 --> 00:03:32,630
names.

34
00:03:33,020 --> 00:03:37,950
So let's say for this one I am going to leave it blank.

35
00:03:38,210 --> 00:03:41,610
I'm just gonna copy this a couple of times.

36
00:03:41,660 --> 00:03:46,350
So inside the names I'm going to add in some strings because your strings.

37
00:03:46,520 --> 00:03:48,930
You need to enclose it in quotes.

38
00:03:49,010 --> 00:03:52,540
So the first one here I'll say John.

39
00:03:53,540 --> 00:03:59,250
And for this one here I'm going to add Jane right.

40
00:03:59,370 --> 00:04:02,130
So notice the first one here.

41
00:04:02,130 --> 00:04:03,900
Line number five.

42
00:04:03,900 --> 00:04:06,190
I have not passed in any value.

43
00:04:06,270 --> 00:04:14,460
So what's gonna happen when I execute this code is going to use the default value that I have set inside

44
00:04:14,460 --> 00:04:25,780
the perimeter here that I defined so let me save my code by pressing control an s. If you are a Mac

45
00:04:25,830 --> 00:04:27,890
you can do command an s.

46
00:04:27,900 --> 00:04:30,810
So once you've saved you could play the file.

47
00:04:31,000 --> 00:04:38,930
So I click on play and you can see the output when I call the function.

48
00:04:38,940 --> 00:04:47,070
I did not pass in any value for the first student name and it then used the default value which was

49
00:04:47,310 --> 00:04:48,630
blue line.

50
00:04:48,770 --> 00:04:49,560
Line 6.

51
00:04:49,590 --> 00:04:53,000
A pastor named John it says hello John.

52
00:04:53,160 --> 00:04:55,130
Line 7 passed in the name Jane.

53
00:04:55,140 --> 00:04:56,190
It says Hello Jane.

54
00:04:56,580 --> 00:05:07,370
So inside the function body I did say I wanted to print the word hello plus whatever names I have supplied.

55
00:05:07,500 --> 00:05:11,040
So the names of supplied when I called the function.

56
00:05:11,040 --> 00:05:19,350
While John again I didn't supply a name for blue line because blue line here is a value the default

57
00:05:19,560 --> 00:05:23,690
parameter value for these names variable.

58
00:05:23,730 --> 00:05:29,790
So that's basically how you use parameter default value.

59
00:05:29,790 --> 00:05:37,890
The key thing to note is that where you have several parameters defined you can only give the default

60
00:05:38,070 --> 00:05:41,480
value to the last parameter in the list.

61
00:05:41,480 --> 00:05:47,610
So if you have several parameters you separate them by a comma and you can only add a default value

62
00:05:47,610 --> 00:05:48,600
to the last one.

63
00:05:48,600 --> 00:05:51,230
This is because of the positioning.

64
00:05:51,380 --> 00:05:51,750
Okay.

65
00:05:51,750 --> 00:05:54,850
The values are signed by position.

66
00:05:54,920 --> 00:05:55,550
That's it.

67
00:05:55,590 --> 00:05:58,050
Thank you for watching and bye for now.
