1
00:00:00,660 --> 00:00:08,760
When you go to order a coffee to the barista, do you say I want a coffee or do you say I want a coffee

2
00:00:08,760 --> 00:00:09,600
in a cup?

3
00:00:11,150 --> 00:00:16,280
Whatever you would say in both cases, you would always get a coffee in a cup.

4
00:00:17,620 --> 00:00:25,420
So people don't say, I want the coffee in a cup, because that is the default argument.

5
00:00:25,420 --> 00:00:27,640
So it is a default input.

6
00:00:28,870 --> 00:00:33,550
The barista always knows that the coffee should be served in a cup.

7
00:00:33,850 --> 00:00:35,890
The same goes in here.

8
00:00:36,520 --> 00:00:40,660
We always use this to do that text file.

9
00:00:40,660 --> 00:00:48,820
So why should we mention it always when when we order the function, When we call the function, when

10
00:00:48,820 --> 00:00:50,020
we order the coffee.

11
00:00:51,280 --> 00:00:55,120
So we do that here and there and there multiple times.

12
00:00:56,780 --> 00:01:03,740
Well, there is a solution for that, and the solution is default arguments or default parameters,

13
00:01:03,740 --> 00:01:05,930
whatever terminology you use.

14
00:01:06,200 --> 00:01:08,510
I'll explain the terminology as well.

15
00:01:09,590 --> 00:01:12,680
So to make this a default parameter.

16
00:01:14,870 --> 00:01:18,640
All you have to do and let's start with get to this function.

17
00:01:18,650 --> 00:01:24,110
All you have to do is assign the value to dos the text to the parameter.

18
00:01:24,770 --> 00:01:33,350
So now this is a default parameter, and therefore we say that this call has a default argument.

19
00:01:33,350 --> 00:01:38,570
So we don't have to provide the actual value of the argument.

20
00:01:38,990 --> 00:01:43,460
So in this case, both terminologies are used interchangeably.

21
00:01:44,120 --> 00:01:46,340
Default argument, default parameter.

22
00:01:47,420 --> 00:01:56,240
So therefore we can remove all these argument values from all the get to this function, which is four

23
00:01:56,240 --> 00:01:58,730
of them like that.

24
00:02:00,190 --> 00:02:02,470
And here as well, the fourth one.

25
00:02:04,450 --> 00:02:10,030
So if I run the code now and I try, for example, the show methods, things will work the same.

26
00:02:14,220 --> 00:02:24,210
The benefits here is that if you ever want to change the value of that parameter, you can simply specify

27
00:02:24,210 --> 00:02:24,930
the new value.

28
00:02:24,930 --> 00:02:29,580
For example, let's say to use one dot text.

29
00:02:30,300 --> 00:02:38,310
So I just changed the value in the get to this call in that condition.

30
00:02:38,310 --> 00:02:44,190
So let me try the code now, run mine and I'll try to add something so that this line is executed.

31
00:02:44,190 --> 00:02:50,550
So add my new to do press enter and we get an error this time.

32
00:02:50,550 --> 00:02:57,420
So it says that no such file or directory to this one dot text the error.

33
00:03:00,150 --> 00:03:02,190
Can be traced in here.

34
00:03:02,190 --> 00:03:05,580
So first it occurred in line.

35
00:03:06,430 --> 00:03:07,630
19.

36
00:03:09,610 --> 00:03:12,160
So errors can be read from top to bottom.

37
00:03:12,160 --> 00:03:13,840
So this is where the error started.

38
00:03:13,840 --> 00:03:15,850
Line 19 and here.

39
00:03:16,690 --> 00:03:23,230
So Python try to call this function and this function itself try to call something else which you see

40
00:03:23,230 --> 00:03:23,650
in here.

41
00:03:23,650 --> 00:03:25,030
So line two.

42
00:03:26,470 --> 00:03:28,570
Is the next one to be executed.

43
00:03:28,600 --> 00:03:29,800
So this one here.

44
00:03:30,810 --> 00:03:38,790
And that line tried to open the two does one the text file, which does not exist.

45
00:03:38,820 --> 00:03:42,720
That's why we get this error in line two.

46
00:03:44,690 --> 00:03:50,600
So what I'm trying to demonstrate here is that you can change default arguments.

47
00:03:50,600 --> 00:03:56,890
You can just give a value here, and that value will replace that value there.

48
00:03:58,310 --> 00:04:00,650
So that's the idea with two fold arguments.

49
00:04:02,470 --> 00:04:07,180
So let me go back here and remove that one and remove the value itself.

50
00:04:07,180 --> 00:04:08,200
We don't need it.

51
00:04:11,260 --> 00:04:17,209
And let's implement default parameters with the right to this function here as well.

52
00:04:17,230 --> 00:04:22,990
So file path would be to do the text.

53
00:04:25,580 --> 00:04:37,760
But to dos or is not a default parameter because we're always having a different list in each of these

54
00:04:37,760 --> 00:04:38,540
conditions.

55
00:04:38,540 --> 00:04:43,070
So in this add condition, the user adds a to do.

56
00:04:43,310 --> 00:04:51,020
They provide it in the command line and then we read the existing to dos using that get to this function

57
00:04:51,050 --> 00:04:55,760
up here and then we append the to do of the user to the list.

58
00:04:55,940 --> 00:05:00,620
So now we have a new list here and we want to provide that new list.

59
00:05:01,860 --> 00:05:03,870
To the right to this function.

60
00:05:03,870 --> 00:05:11,820
So there's no way for the right to do this function to have an assumption on what this value could be.

61
00:05:12,660 --> 00:05:15,660
So there is no assumption you want to keep.

62
00:05:16,540 --> 00:05:17,860
Parameters as.

63
00:05:18,920 --> 00:05:21,560
Non default parameters.

64
00:05:21,650 --> 00:05:23,690
So that is a default parameter.

65
00:05:23,690 --> 00:05:25,850
That is a known default parameter.

66
00:05:26,390 --> 00:05:32,120
Now we have this error here, so it says non default parameter follows default parameters.

67
00:05:32,120 --> 00:05:40,940
So this is a problem and it can be fixed by putting this non default parameter before the default parameters.

68
00:05:40,940 --> 00:05:44,480
So that is the correct syntax.

69
00:05:44,480 --> 00:05:46,970
Otherwise you will get an error.

70
00:05:51,720 --> 00:05:56,130
That also means that you should change the positions of these.

71
00:05:58,120 --> 00:06:06,280
Arguments when you call the function, because what's happening now is if I run the script, run main

72
00:06:06,550 --> 00:06:17,380
and I add my new to do so, we get an error and it started in line.

73
00:06:18,430 --> 00:06:19,570
23.

74
00:06:20,850 --> 00:06:21,510
And here.

75
00:06:21,510 --> 00:06:29,490
So this is the function code we just wrote, and then it traces back to line eight where the function

76
00:06:29,490 --> 00:06:30,780
definition is.

77
00:06:33,250 --> 00:06:39,700
And the error is that this function expected a string, right?

78
00:06:39,700 --> 00:06:42,610
Like to dos the text, for example.

79
00:06:42,640 --> 00:06:45,250
But in reality it got a list.

80
00:06:45,250 --> 00:06:50,410
And that is because the order of the arguments matter here.

81
00:06:50,590 --> 00:06:52,930
So if this is a first.

82
00:06:54,350 --> 00:06:55,490
Value you place.

83
00:06:55,520 --> 00:07:00,980
That value will go as the value of the first parameter.

84
00:07:00,980 --> 00:07:03,380
So to do arc is actually.

85
00:07:04,200 --> 00:07:08,250
The string while fall path is going to be the list.

86
00:07:09,430 --> 00:07:13,120
So basically what we did is we set five paths.

87
00:07:13,480 --> 00:07:19,690
Five path is equal to the list, which had like multiple to dos to do one and so on.

88
00:07:20,980 --> 00:07:21,780
That's what we did.

89
00:07:21,790 --> 00:07:30,220
So the open function is confused and it cannot open a file which has a path, a list, so it doesn't

90
00:07:30,220 --> 00:07:30,970
make sense.

91
00:07:31,420 --> 00:07:34,540
Therefore, you should respect the older now.

92
00:07:35,690 --> 00:07:37,640
To do should go first.

93
00:07:41,760 --> 00:07:50,580
And then to reduce the text or or if you don't like order, what you could do is you could.

94
00:07:52,400 --> 00:07:53,990
Let me undo this.

95
00:07:55,610 --> 00:08:03,350
So if you really want to have the order as you wish, then you could say fault path is equal to that

96
00:08:03,950 --> 00:08:04,730
and to do.

97
00:08:05,330 --> 00:08:07,430
Org is equal to that.

98
00:08:07,640 --> 00:08:12,740
So if you explicitly mention the argument names, then you don't have to respect the order.

99
00:08:12,770 --> 00:08:14,300
This will work now.

100
00:08:17,180 --> 00:08:20,300
So show and add new order.

101
00:08:21,710 --> 00:08:24,560
And new order is part of the two two items.

102
00:08:26,060 --> 00:08:31,310
However, I wouldn't recommend this method unless you have to.

103
00:08:34,390 --> 00:08:35,710
So just say.

104
00:08:39,100 --> 00:08:45,580
To do so first and then to dos the text.

105
00:08:49,540 --> 00:08:55,390
So to do that goes to to to talk to those that text goes to file path.

106
00:08:55,750 --> 00:09:03,160
Actually, since file path is default as is a default parameter, you don't even have to pass file path.

107
00:09:03,170 --> 00:09:05,350
So you just say to dos and that's it.

108
00:09:05,890 --> 00:09:09,220
So if I run the ad.

109
00:09:10,490 --> 00:09:14,140
We just made a default talk

110
00:09:16,490 --> 00:09:20,210
show and that's the new to do.

111
00:09:25,310 --> 00:09:31,760
So what we did is now we only mention that file path in there because it is not important.

112
00:09:31,760 --> 00:09:36,320
We don't have to pollute our code with unnecessary details all the time.

113
00:09:36,470 --> 00:09:39,260
Just like the cup, the coffee cup example.

114
00:09:39,260 --> 00:09:40,820
You don't have to say all the time.

115
00:09:40,820 --> 00:09:45,650
I want the coffee in a cup because that's the default behavior.

116
00:09:46,430 --> 00:09:51,000
So let's see, what else should we change here, right to do?

117
00:09:51,440 --> 00:09:59,090
Just remove to use the text and leave only that same here.

118
00:10:05,220 --> 00:10:06,240
And that's about it.

119
00:10:07,750 --> 00:10:15,610
Before I close the video, I want to also emphasize that I also built in functions can have default

120
00:10:15,610 --> 00:10:16,350
parameters.

121
00:10:16,360 --> 00:10:24,940
For example, if you say help input, you see the help string of the input function, you'll see that

122
00:10:24,940 --> 00:10:26,230
the prompt.

123
00:10:28,120 --> 00:10:32,560
Parameter is set by default to a non object.

124
00:10:34,270 --> 00:10:41,200
So that makes it possible for you to just say inputs without providing a string.

125
00:10:42,480 --> 00:10:49,080
So if you say like that, there will not be any string printed out here, no prompt.

126
00:10:49,080 --> 00:10:51,450
You just enter this as a user and so on.

127
00:10:51,570 --> 00:10:57,120
But if you provide that string, that string will be displayed in here.

128
00:11:01,010 --> 00:11:06,660
Some functions, though, such as Len.

129
00:11:06,860 --> 00:11:12,250
So this is a function that returns the length of a list or a string.

130
00:11:12,260 --> 00:11:13,340
So, for example.

131
00:11:13,400 --> 00:11:14,090
Hello?

132
00:11:14,120 --> 00:11:18,350
It tells you it has five items, so five characters.

133
00:11:18,350 --> 00:11:21,020
So if you do help.

134
00:11:23,330 --> 00:11:27,560
Len, you'll see that this doesn't have a default parameter.

135
00:11:28,610 --> 00:11:31,700
So the object is mandatory.

136
00:11:33,320 --> 00:11:37,970
That means if you do, Len, with votes and arguments, you're going to get an error.

137
00:11:38,780 --> 00:11:43,280
You see, Len takes exactly one argument, but you didn't give anything.

138
00:11:45,970 --> 00:11:55,990
We would get the same error if we change this, get to this function, to this.

139
00:11:56,410 --> 00:12:04,360
So if you just leave file path as a non default argument, then in get to dos, you don't mention the

140
00:12:04,360 --> 00:12:09,100
value of that file path and if you execute the code now.

141
00:12:11,110 --> 00:12:20,350
And you try to add a brand new to do you get an error in line 19 here.

142
00:12:20,860 --> 00:12:29,230
So the function called tried to execute the function definition, but it couldn't because the function

143
00:12:29,230 --> 00:12:33,460
calls should have gotten one argument file path.

144
00:12:36,280 --> 00:12:46,960
So I hope that makes sense that if you have a default value for the parameter, then you don't have

145
00:12:46,960 --> 00:12:50,050
to pass it here, otherwise you will get an error.

146
00:12:51,070 --> 00:12:52,660
So that's about this video.

147
00:12:52,780 --> 00:12:53,470
Thanks a lot.

148
00:12:53,500 --> 00:12:54,160
See you later.

