1
00:00:00,000 --> 00:00:01,000
Hello guys.

2
00:00:01,000 --> 00:00:04,000
So we are going to continue the discussion with respect to Python.

3
00:00:04,000 --> 00:00:09,000
And in this video we are going to discuss about the most important module that is called as functions.

4
00:00:09,000 --> 00:00:11,000
So what is the entire video outline?

5
00:00:11,000 --> 00:00:15,000
In this video I will be discussing about what exactly is functions.

6
00:00:15,000 --> 00:00:16,000
Why do we require functions?

7
00:00:16,000 --> 00:00:20,000
Along with that, we'll also be seeing about uh, calling a function.

8
00:00:20,000 --> 00:00:21,000
Defining a function.

9
00:00:21,000 --> 00:00:22,000
How do we define it.

10
00:00:22,000 --> 00:00:23,000
What is the syntax of it.

11
00:00:23,000 --> 00:00:28,000
Then along with that we'll be discussing about functions parameter default parameters.

12
00:00:28,000 --> 00:00:30,000
Then what is variable length arguments.

13
00:00:30,000 --> 00:00:31,000
You know.

14
00:00:31,000 --> 00:00:36,000
So there are some very important arguments like positional argument and keyword argument will be discussing

15
00:00:36,000 --> 00:00:37,000
about that.

16
00:00:37,000 --> 00:00:41,000
Then we will also be discussing about return statement.

17
00:00:41,000 --> 00:00:46,000
So we will be covering each and every thing uh, with the help of again code with the help of Python.

18
00:00:46,000 --> 00:00:46,000
Yeah.

19
00:00:46,000 --> 00:00:49,000
Each and every thing will try to write it down with multiple examples.

20
00:00:49,000 --> 00:00:55,000
And, uh, I'll be making sure that you understand this because this is one of the most important thing,

21
00:00:55,000 --> 00:01:00,000
because whenever we are writing any data science projects or Python projects, we will be definitely

22
00:01:00,000 --> 00:01:01,000
using a lot of functions.

23
00:01:01,000 --> 00:01:05,000
So first of all, let's go ahead and define the function.

24
00:01:05,000 --> 00:01:08,000
A function is a block of code okay.

25
00:01:08,000 --> 00:01:09,000
Again I'm repeating it.

26
00:01:09,000 --> 00:01:13,000
A function is a block of code that performs a specific task.

27
00:01:13,000 --> 00:01:19,000
A functions help in organizing code, reusing code, and improving readability.

28
00:01:19,000 --> 00:01:23,000
Okay, so it is a block of code that performs a specific task.

29
00:01:23,000 --> 00:01:27,000
It helps in organizing code, reusing code, and improving readability.

30
00:01:27,000 --> 00:01:31,000
One of the best syntax if you really want to check it out right.

31
00:01:31,000 --> 00:01:32,000
So this is the syntax.

32
00:01:32,000 --> 00:01:35,000
So here I'm just going to give you the syntax.

33
00:01:35,000 --> 00:01:37,000
This function is an empty function.

34
00:01:37,000 --> 00:01:41,000
I've just written it for the for just to make you understand.

35
00:01:41,000 --> 00:01:44,000
So first of all, a function starts with a definition keyword.

36
00:01:44,000 --> 00:01:47,000
Then you have the function name.

37
00:01:47,000 --> 00:01:49,000
And if any parameters that you are defining.

38
00:01:49,000 --> 00:01:51,000
So we have to define the parameters.

39
00:01:51,000 --> 00:01:53,000
This is doc string.

40
00:01:53,000 --> 00:01:59,000
Uh doc string is just to use to uh, you know, write some kind of comments, what the specific function

41
00:01:59,000 --> 00:02:04,000
does so that any developer will be able to understand it.

42
00:02:04,000 --> 00:02:07,000
Along with that, we will go ahead and write our function body.

43
00:02:07,000 --> 00:02:11,000
Function body is more about all the code that we are going to use inside the function.

44
00:02:11,000 --> 00:02:14,000
And then finally we return some kind of value okay.

45
00:02:14,000 --> 00:02:17,000
It is not necessary that uh return should be there.

46
00:02:17,000 --> 00:02:22,000
Some of the functions may not have return value, but some of the functions will definitely have a lot

47
00:02:22,000 --> 00:02:23,000
of return value.

48
00:02:23,000 --> 00:02:24,000
Okay.

49
00:02:24,000 --> 00:02:27,000
So uh, this is the basic syntax.

50
00:02:27,000 --> 00:02:33,000
Now let me just go ahead and tell or talk about why do we require function okay.

51
00:02:33,000 --> 00:02:34,000
Why functions.

52
00:02:34,000 --> 00:02:37,000
This is important for everybody to understand.

53
00:02:38,000 --> 00:02:40,000
Let's say I am creating a number variable.

54
00:02:41,000 --> 00:02:47,000
And I go ahead and write a code which will be able to check whether a number is even or odd.

55
00:02:47,000 --> 00:02:53,000
So suppose if I go ahead and write if num modulus two or percentile two is double equal to zero, then

56
00:02:53,000 --> 00:02:58,000
obviously I'll say hey, print the number is even right.

57
00:02:58,000 --> 00:02:59,000
So I'm just going to write.

58
00:02:59,000 --> 00:03:01,000
The number is even else.

59
00:03:01,000 --> 00:03:05,000
What I usually do is that in this I will go ahead and print and write.

60
00:03:06,000 --> 00:03:10,000
The number is odd right.

61
00:03:10,000 --> 00:03:14,000
So here what exactly is basically happening.

62
00:03:14,000 --> 00:03:16,000
We are just going to check whether a number is even or odd.

63
00:03:16,000 --> 00:03:21,000
And obviously if I go ahead and execute this condition will be true because the number is even and I'm

64
00:03:21,000 --> 00:03:23,000
going to get the answer, the number is even.

65
00:03:23,000 --> 00:03:23,000
Okay.

66
00:03:24,000 --> 00:03:30,000
Now let's say in my project I want to write this piece of code, and I need to reuse this piece of code

67
00:03:30,000 --> 00:03:36,000
in multiple places, because in multiple places I'm going to check whether a number is odd or even right

68
00:03:36,000 --> 00:03:42,000
now, in this case, what I have to do, I have to copy the same code, use it in multiple files instead

69
00:03:42,000 --> 00:03:43,000
of this.

70
00:03:43,000 --> 00:03:47,000
A better way of reusing the entire code will be with the help of functions.

71
00:03:47,000 --> 00:03:48,000
Now what?

72
00:03:48,000 --> 00:03:51,000
I will do this entire code I will write inside a function.

73
00:03:51,000 --> 00:03:56,000
Now the best way to write is that let's say I will go ahead and create my definition keyword.

74
00:03:56,000 --> 00:03:59,000
I will say hey, my function name is even or odd, okay?

75
00:04:00,000 --> 00:04:03,000
And this will specifically take a parameter which is called as number.

76
00:04:04,000 --> 00:04:07,000
And now I will go ahead and write my condition inside this.

77
00:04:07,000 --> 00:04:08,000
Right.

78
00:04:08,000 --> 00:04:14,000
So as soon as I go ahead and press enter, that basically means I'm inside my function.

79
00:04:14,000 --> 00:04:14,000
Right?

80
00:04:14,000 --> 00:04:18,000
So automatically the indentation goes inside this function block.

81
00:04:18,000 --> 00:04:23,000
Right now the first thing is that I can go ahead and write my doc string.

82
00:04:23,000 --> 00:04:33,000
The doc string will be like, hey, this function performs, um, finds even or odd okay, even or odd.

83
00:04:33,000 --> 00:04:36,000
So this is what I'm specifically writing over here.

84
00:04:36,000 --> 00:04:37,000
So this becomes my dog string.

85
00:04:37,000 --> 00:04:40,000
It is not compulsory that you really need to write a dog string.

86
00:04:40,000 --> 00:04:43,000
You can leave it completely empty.

87
00:04:43,000 --> 00:04:48,000
Uh, and you may also not even write any of these things, but it is a good practice that we should

88
00:04:48,000 --> 00:04:51,000
definitely write some information about the function itself.

89
00:04:51,000 --> 00:04:55,000
Uh, now I will go ahead and write my code inside this.

90
00:04:55,000 --> 00:04:56,000
Now I will go ahead and write.

91
00:04:56,000 --> 00:05:01,000
If num num is nothing but the same, uh, parameter that I'm actually getting.

92
00:05:01,000 --> 00:05:02,000
And this is basically my parameter.

93
00:05:02,000 --> 00:05:08,000
If num percentile two is double equal to zero, I will go ahead and print the.

94
00:05:10,000 --> 00:05:20,000
The the number is even or I will go ahead and write else print.

95
00:05:23,000 --> 00:05:24,000
The number is odd.

96
00:05:24,000 --> 00:05:25,000
Right.

97
00:05:25,000 --> 00:05:28,000
So here you can see I've defined this entire function.

98
00:05:28,000 --> 00:05:31,000
Now I'll go just go ahead and press it and execute it.

99
00:05:31,000 --> 00:05:32,000
Right.

100
00:05:32,000 --> 00:05:36,000
So as soon as I execute it I have actually created my first function.

101
00:05:36,000 --> 00:05:36,000
Right.

102
00:05:36,000 --> 00:05:37,000
And this is amazing.

103
00:05:37,000 --> 00:05:41,000
And if you have also created it, always make sure the indentation is managed.

104
00:05:41,000 --> 00:05:45,000
If the indentation is right then everything is going to work fine.

105
00:05:45,000 --> 00:05:48,000
Okay, let's see if I miss out the indentation I executed.

106
00:05:48,000 --> 00:05:49,000
I will be getting an error.

107
00:05:49,000 --> 00:05:54,000
It will be saying hey, expected an independent block after the if statement and this is what we have

108
00:05:54,000 --> 00:05:56,000
actually done okay.

109
00:05:56,000 --> 00:05:58,000
So I'll just say Ctrl Z.

110
00:05:58,000 --> 00:05:59,000
Yeah.

111
00:05:59,000 --> 00:06:00,000
Now we are fine.

112
00:06:00,000 --> 00:06:02,000
I'll go ahead and create my function even or odd.

113
00:06:02,000 --> 00:06:04,000
Now in order to call this function.

114
00:06:04,000 --> 00:06:09,000
So let's call this function now wherever I want to use this code to find.

115
00:06:09,000 --> 00:06:13,000
Even or odd, I will just call this function okay.

116
00:06:13,000 --> 00:06:14,000
In order to call this function just go.

117
00:06:14,000 --> 00:06:17,000
Ahead and call the function name.

118
00:06:17,000 --> 00:06:21,000
And here you just need to provide your parameter right.

119
00:06:21,000 --> 00:06:24,000
So let's say the number parameter that I'm giving I want to give it as 24.

120
00:06:24,000 --> 00:06:30,000
Now if I go ahead and execute it here you can see that automatically it is printing the number is even.

121
00:06:30,000 --> 00:06:33,000
Because as soon as I give the parameter it went over here.

122
00:06:33,000 --> 00:06:35,000
It went and checked all this condition.

123
00:06:35,000 --> 00:06:37,000
Whichever is true, it printed it right.

124
00:06:38,000 --> 00:06:42,000
A very simple way of creating a function and calling a function.

125
00:06:42,000 --> 00:06:44,000
And why do we require a function?

126
00:06:44,000 --> 00:06:46,000
Because every way we cannot write the code.

127
00:06:46,000 --> 00:06:48,000
We need to reuse this kind of code.

128
00:06:48,000 --> 00:06:54,000
So whenever you think, okay I have some set of code block which I really need to reuse it, I will

129
00:06:54,000 --> 00:06:59,000
try to create that entire thing inside a function itself, and I'll reuse it.

130
00:06:59,000 --> 00:06:59,000
Right.

131
00:06:59,000 --> 00:07:04,000
So through this, the most important thing will be that it helps in organizing code, reusing code,

132
00:07:04,000 --> 00:07:07,000
and improving readability, improving readability.

133
00:07:07,000 --> 00:07:07,000
Why?

134
00:07:07,000 --> 00:07:12,000
Because we are also writing some amazing docstring over here so that we'll be able to understand, because

135
00:07:12,000 --> 00:07:16,000
in a company, many people will work, many people will write different, different code over there,

136
00:07:16,000 --> 00:07:17,000
multiple modules will be built.

137
00:07:17,000 --> 00:07:18,000
Okay.

138
00:07:18,000 --> 00:07:22,000
So this was a basic example with respect to function.

139
00:07:22,000 --> 00:07:26,000
I've also spoken about a parameter like what exactly is a parameter?

140
00:07:26,000 --> 00:07:28,000
How do you give a parameter in this?

141
00:07:29,000 --> 00:07:33,000
Now there may be scenario that I may also have multiple parameters.

142
00:07:33,000 --> 00:07:35,000
So let's work with multiple parameter.

143
00:07:35,000 --> 00:07:43,000
So here I will go ahead and write function with multiple parameters okay.

144
00:07:45,000 --> 00:07:48,000
And parameters can give integer string whatever things you require.

145
00:07:48,000 --> 00:07:50,000
So I will go ahead and write definition.

146
00:07:50,000 --> 00:07:56,000
And let's say I want to go ahead and create a add function to add two numbers.

147
00:07:56,000 --> 00:07:59,000
So I will go ahead and write definition, add a comma b.

148
00:07:59,000 --> 00:08:04,000
And let's say I go ahead and write my docstring again not compulsory.

149
00:08:04,000 --> 00:08:06,000
I can also leave it like this.

150
00:08:06,000 --> 00:08:06,000
Okay.

151
00:08:06,000 --> 00:08:07,000
Just to show it to you.

152
00:08:07,000 --> 00:08:09,000
That is the reason I'm writing.

153
00:08:09,000 --> 00:08:09,000
Okay.

154
00:08:09,000 --> 00:08:11,000
So I will go back over here, press enter.

155
00:08:11,000 --> 00:08:15,000
So I'm inside this particular code block.

156
00:08:15,000 --> 00:08:18,000
Now I know that I have to add two variables right.

157
00:08:18,000 --> 00:08:19,000
So I will create.

158
00:08:19,000 --> 00:08:24,000
One way is that I will create a variable c a plus b okay.

159
00:08:24,000 --> 00:08:30,000
And then I can return this c output from that particular function okay.

160
00:08:30,000 --> 00:08:34,000
Return c plus uh c which is nothing but a plus b.

161
00:08:34,000 --> 00:08:37,000
Whatever sum is there, we are just going to return it.

162
00:08:37,000 --> 00:08:39,000
A better way of writing the code.

163
00:08:39,000 --> 00:08:43,000
Instead of writing C, I can directly write return a plus B, right?

164
00:08:43,000 --> 00:08:44,000
So here what we are doing.

165
00:08:44,000 --> 00:08:47,000
We just returning the sum of a and b.

166
00:08:47,000 --> 00:08:54,000
Now all I have to do is that create a variable and add call this add function.

167
00:08:54,000 --> 00:08:56,000
Here I'm going to give two comma four.

168
00:08:56,000 --> 00:09:00,000
Now what is going to get what value result is going to get.

169
00:09:00,000 --> 00:09:05,000
As soon as we call this function two comma four it will just return two plus four.

170
00:09:05,000 --> 00:09:08,000
Whatever will be the result like six it will be stored over here.

171
00:09:08,000 --> 00:09:16,000
Now if I go ahead and print the result here, you'll be able to see that I am able to get the six value.

172
00:09:16,000 --> 00:09:20,000
So here you can have any number of parameters and code.

173
00:09:20,000 --> 00:09:24,000
Whatever things you are writing, you can basically use this parameter and write any code that you want.

174
00:09:24,000 --> 00:09:25,000
Okay.

175
00:09:25,000 --> 00:09:29,000
So, uh, it is up to you what kind of function that you are building.

176
00:09:29,000 --> 00:09:34,000
And as we go ahead with multiple examples, if we see in the future and in the upcoming videos will

177
00:09:34,000 --> 00:09:39,000
be writing very complex functions, there is there is something called as decorators lambda function.

178
00:09:39,000 --> 00:09:41,000
Many things will be probably coming one by one.

179
00:09:41,000 --> 00:09:42,000
We will be learning first.

180
00:09:42,000 --> 00:09:43,000
We will start with basics.

181
00:09:43,000 --> 00:09:49,000
Then slowly, slowly will be building the blocks with respect to the learning and then we will be continuing

182
00:09:49,000 --> 00:09:49,000
on.

183
00:09:49,000 --> 00:09:55,000
Okay, now let me just go ahead and show you and talk about one very important thing, which is called

184
00:09:55,000 --> 00:09:57,000
as default parameters.

185
00:09:57,000 --> 00:10:01,000
We can also provide default parameters within our function.

186
00:10:01,000 --> 00:10:01,000
Okay.

187
00:10:01,000 --> 00:10:03,000
Now what exactly is default parameters.

188
00:10:04,000 --> 00:10:11,000
Let's say I create a function okay I create a function saying as definition greed okay.

189
00:10:11,000 --> 00:10:12,000
definition greet.

190
00:10:12,000 --> 00:10:14,000
This function is responsible.

191
00:10:14,000 --> 00:10:18,000
Uh, let's say I give a name over here, right?

192
00:10:18,000 --> 00:10:20,000
Let's say one parameter is name.

193
00:10:20,000 --> 00:10:21,000
Okay.

194
00:10:21,000 --> 00:10:24,000
And here I'm just going to write print.

195
00:10:25,000 --> 00:10:25,000
Okay.

196
00:10:26,000 --> 00:10:34,000
Uh I'll use the f string and say that okay I want to probably, um, write some information.

197
00:10:34,000 --> 00:10:37,000
Let's say I want to say hello.

198
00:10:37,000 --> 00:10:40,000
Hello, whatever the person name is.

199
00:10:40,000 --> 00:10:41,000
Okay.

200
00:10:41,000 --> 00:10:43,000
So I'm going to just go ahead and print this okay.

201
00:10:43,000 --> 00:10:45,000
And this is what is my definition.

202
00:10:45,000 --> 00:10:49,000
Grid rate is just more like a welcoming someone okay.

203
00:10:49,000 --> 00:10:50,000
Welcoming someone.

204
00:10:50,000 --> 00:10:53,000
Now what I will do is that I will just go ahead.

205
00:10:54,000 --> 00:10:56,000
Just go ahead and call this function.

206
00:10:56,000 --> 00:10:58,000
So I will go ahead and write, greet.

207
00:10:58,000 --> 00:11:01,000
And let me say that Krish has entered somewhere.

208
00:11:01,000 --> 00:11:05,000
So I will just give the Krish parameter like let's say you are entering a restaurant and as soon as

209
00:11:05,000 --> 00:11:12,000
you write Krish over there in one of the application and suddenly I will get a message saying that.

210
00:11:12,000 --> 00:11:12,000
Hello Krish.

211
00:11:12,000 --> 00:11:13,000
Okay.

212
00:11:13,000 --> 00:11:15,000
Or welcome something like this.

213
00:11:15,000 --> 00:11:19,000
Welcome to the Paradise.

214
00:11:19,000 --> 00:11:21,000
Let's say this is my message.

215
00:11:21,000 --> 00:11:22,000
Hello, Krish.

216
00:11:22,000 --> 00:11:23,000
Welcome to the Paradise.

217
00:11:23,000 --> 00:11:28,000
So as soon as I give this parameter automatically, this will get replaced over here.

218
00:11:28,000 --> 00:11:28,000
Okay.

219
00:11:29,000 --> 00:11:33,000
Now I may also give one parameter.

220
00:11:33,000 --> 00:11:36,000
I may also give some parameters with a default value.

221
00:11:36,000 --> 00:11:36,000
Okay.

222
00:11:36,000 --> 00:11:38,000
With a default value.

223
00:11:38,000 --> 00:11:39,000
Now what does that particular mean okay.

224
00:11:40,000 --> 00:11:47,000
Let's say I just go over here and this time I don't give Chris okay I'll just try to execute this without

225
00:11:47,000 --> 00:11:49,000
giving any parameter.

226
00:11:49,000 --> 00:11:51,000
So here you can see I will be getting an error.

227
00:11:51,000 --> 00:11:52,000
Hey, greet.

228
00:11:52,000 --> 00:11:54,000
Missing one requirement positional argument.

229
00:11:54,000 --> 00:11:56,000
Okay, we'll talk about what exactly is positional argument.

230
00:11:56,000 --> 00:11:57,000
More about it.

231
00:11:57,000 --> 00:12:02,000
But here you can see that I have given this particular, uh, name parameter over here, but I have

232
00:12:02,000 --> 00:12:04,000
not given any parameter when I'm calling it.

233
00:12:04,000 --> 00:12:06,000
And that is the reason I'm getting this one.

234
00:12:06,000 --> 00:12:08,000
Missing one required positional argument.

235
00:12:08,000 --> 00:12:08,000
Okay.

236
00:12:08,000 --> 00:12:14,000
Now, in order to solve this problem, what I can do, I will say, since I am not giving the name,

237
00:12:14,000 --> 00:12:17,000
I may give a default value to the name.

238
00:12:17,000 --> 00:12:21,000
Let's say if I'm not giving it over here, then what will happen?

239
00:12:21,000 --> 00:12:26,000
It will first of all, go and see whether, uh, the greet name is equal to guest is given or not.

240
00:12:27,000 --> 00:12:32,000
Now, if I go ahead and execute this, see, I'm not giving any parameter but the default parameter,

241
00:12:32,000 --> 00:12:34,000
it will take it as guest.

242
00:12:34,000 --> 00:12:34,000
Okay.

243
00:12:34,000 --> 00:12:37,000
So if I go ahead and execute it here you can see.

244
00:12:37,000 --> 00:12:37,000
Hello guest.

245
00:12:37,000 --> 00:12:39,000
Welcome to the Paradise.

246
00:12:39,000 --> 00:12:42,000
Let's say if I go ahead and give the name okay.

247
00:12:42,000 --> 00:12:45,000
Over here, let's say the guest is not interested to give the name.

248
00:12:45,000 --> 00:12:47,000
So by default it will take it as guest.

249
00:12:47,000 --> 00:12:49,000
But if I'm giving my name, it will just replace.

250
00:12:49,000 --> 00:12:51,000
The guest will get replaced with crush.

251
00:12:51,000 --> 00:12:57,000
Okay, so this is, uh, some good example with respect to the default parameters.

252
00:12:57,000 --> 00:12:59,000
And this is how you can also assign default parameters.

253
00:13:00,000 --> 00:13:05,000
Now we are going to discuss about the main topic which you will be seeing in function.

254
00:13:05,000 --> 00:13:14,000
That is nothing but variable length length arguments okay.

255
00:13:15,000 --> 00:13:19,000
Now in the variable length arguments here we are going to discuss about two things.

256
00:13:19,000 --> 00:13:24,000
One is positional and keyword argument okay.

257
00:13:24,000 --> 00:13:24,000
Okay.

258
00:13:25,000 --> 00:13:27,000
Positional and keyword argument.

259
00:13:27,000 --> 00:13:27,000
Okay.

260
00:13:28,000 --> 00:13:29,000
Keywords.

261
00:13:30,000 --> 00:13:31,000
Arguments.

262
00:13:32,000 --> 00:13:32,000
Okay.

263
00:13:33,000 --> 00:13:37,000
Now let me do let me tell you one very important thing.

264
00:13:37,000 --> 00:13:41,000
Let's say that I have in a function many, many parameters as such.

265
00:13:41,000 --> 00:13:42,000
Okay.

266
00:13:42,000 --> 00:13:51,000
And let me just define one simple function that is called as definition print underscore numbers.

267
00:13:51,000 --> 00:13:52,000
Okay.

268
00:13:52,000 --> 00:13:58,000
And here inside this let's say I have like this okay.

269
00:13:58,000 --> 00:13:58,000
Number one.

270
00:13:58,000 --> 00:13:59,000
Number two.

271
00:13:59,000 --> 00:14:00,000
Number three.

272
00:14:00,000 --> 00:14:01,000
Number four.

273
00:14:01,000 --> 00:14:02,000
Number five.

274
00:14:02,000 --> 00:14:04,000
Like this I have many, many parameters.

275
00:14:04,000 --> 00:14:05,000
In short okay.

276
00:14:05,000 --> 00:14:12,000
It's just not one single parameter I can I am basically having many, many, many many parameters.

277
00:14:12,000 --> 00:14:12,000
Okay.

278
00:14:12,000 --> 00:14:17,000
So what I will do instead of just writing all the parameter names, right?

279
00:14:17,000 --> 00:14:23,000
I will use one very simple positional argument which we denote it as star args.

280
00:14:24,000 --> 00:14:24,000
Okay.

281
00:14:24,000 --> 00:14:26,000
Now it is not necessary.

282
00:14:26,000 --> 00:14:27,000
You need to write star args.

283
00:14:27,000 --> 00:14:29,000
I can go ahead and write star crush also.

284
00:14:29,000 --> 00:14:30,000
Okay.

285
00:14:30,000 --> 00:14:32,000
Uh, but it is always a good practice.

286
00:14:32,000 --> 00:14:34,000
What is followed throughout the entire world?

287
00:14:34,000 --> 00:14:36,000
The same practice we should also do.

288
00:14:36,000 --> 00:14:38,000
Now, in this particular case, I will just show you it.

289
00:14:38,000 --> 00:14:39,000
its star crush.

290
00:14:39,000 --> 00:14:44,000
Then we will go ahead and write with the documentation like what is the best practices?

291
00:14:44,000 --> 00:14:46,000
Argument we specifically use?

292
00:14:46,000 --> 00:14:50,000
Like positional arguments is basically given by star args.

293
00:14:50,000 --> 00:14:53,000
As I said, it need not be a args.

294
00:14:53,000 --> 00:14:54,000
I can also write crush.

295
00:14:54,000 --> 00:14:58,000
Okay, now I will go ahead and go ahead inside this particular function.

296
00:14:58,000 --> 00:15:00,000
Now here what I will do.

297
00:15:00,000 --> 00:15:04,000
As you know, the Star crush will be having multiple parameters.

298
00:15:04,000 --> 00:15:10,000
So I what I will do, I will just go ahead and write for numbers in creche.

299
00:15:10,000 --> 00:15:10,000
Okay.

300
00:15:10,000 --> 00:15:12,000
Which is my argument.

301
00:15:12,000 --> 00:15:15,000
I will go ahead and print numbers okay.

302
00:15:16,000 --> 00:15:16,000
Okay.

303
00:15:16,000 --> 00:15:18,000
I will go ahead and print number okay.

304
00:15:18,000 --> 00:15:19,000
Now see this okay.

305
00:15:20,000 --> 00:15:21,000
So this becomes my function.

306
00:15:21,000 --> 00:15:23,000
Please observe very carefully okay.

307
00:15:23,000 --> 00:15:30,000
Now my print underscore numbers function when I'm calling, let's say I have one comma, two comma,

308
00:15:30,000 --> 00:15:33,000
three comma, four comma, five comma, six comma crush.

309
00:15:33,000 --> 00:15:35,000
It can be anything okay.

310
00:15:35,000 --> 00:15:37,000
So these are all the parameters that I have.

311
00:15:37,000 --> 00:15:39,000
You can see it is a set of parameters.

312
00:15:39,000 --> 00:15:43,000
And this parameters are basically called as positional arguments okay.

313
00:15:43,000 --> 00:15:46,000
Positional arguments one after the other.

314
00:15:46,000 --> 00:15:53,000
Now if I go ahead and execute now see the magic this all the parameters will be referenced by Star Crush.

315
00:15:53,000 --> 00:15:57,000
Okay, so crush will be a variable which will be referring all this particular positional arguments.

316
00:15:57,000 --> 00:16:02,000
Now if I go ahead and execute it now clearly here you can see for all the numbers it is being able to

317
00:16:02,000 --> 00:16:03,000
iterate through this.

318
00:16:03,000 --> 00:16:05,000
Right 1234.

319
00:16:05,000 --> 00:16:07,000
And it is displaying it something like this okay.

320
00:16:07,000 --> 00:16:09,000
Because here I just used one.

321
00:16:09,000 --> 00:16:13,000
So this star crush is basically referring to all the positional arguments, right?

322
00:16:13,000 --> 00:16:16,000
Positional arguments basically means all the arguments that is given over here.

323
00:16:17,000 --> 00:16:23,000
Okay, now, as I always said, the best practice would be I will go ahead and write this and I will

324
00:16:23,000 --> 00:16:24,000
say args.

325
00:16:24,000 --> 00:16:28,000
Okay, so args is a kind of argument positional argument that we basically use.

326
00:16:28,000 --> 00:16:29,000
Okay.

327
00:16:29,000 --> 00:16:33,000
So here I'm going to write positional arguments okay.

328
00:16:34,000 --> 00:16:38,000
Why it is important because I may have many number of arguments over there okay.

329
00:16:38,000 --> 00:16:41,000
So I may directly use this specific thing okay.

330
00:16:41,000 --> 00:16:46,000
Now the other thing will be that okay, this is fine if I go ahead and execute it.

331
00:16:46,000 --> 00:16:51,000
And if I execute the same thing okay, I will be able to get the same answer.

332
00:16:51,000 --> 00:16:51,000
Fine.

333
00:16:51,000 --> 00:16:51,000
Perfect.

334
00:16:51,000 --> 00:16:53,000
123456.

335
00:16:53,000 --> 00:16:53,000
Crash.

336
00:16:53,000 --> 00:17:00,000
Now there is also one more important function which is called as keyword argument.

337
00:17:02,000 --> 00:17:02,000
Okay.

338
00:17:02,000 --> 00:17:04,000
Now what exactly is keyword argument?

339
00:17:04,000 --> 00:17:04,000
Okay.

340
00:17:05,000 --> 00:17:09,000
Um, let me just go ahead and create, uh, one more function.

341
00:17:09,000 --> 00:17:09,000
Okay.

342
00:17:09,000 --> 00:17:13,000
Let's say I will go ahead and write, uh, print uh, sorry.

343
00:17:13,000 --> 00:17:16,000
Definition print underscore detail.

344
00:17:16,000 --> 00:17:22,000
Now how it is different from positional argument you'll be able to understand keyword argument is given

345
00:17:22,000 --> 00:17:23,000
by double star.

346
00:17:24,000 --> 00:17:26,000
And you can write any parameter that you have.

347
00:17:26,000 --> 00:17:34,000
So usually the best uh practice that is basically used is k w a r g s k w basically means keyword argument,

348
00:17:34,000 --> 00:17:34,000
right?

349
00:17:34,000 --> 00:17:37,000
ARGs is a simple positional argument.

350
00:17:37,000 --> 00:17:40,000
Now inside this let me do one thing.

351
00:17:41,000 --> 00:17:45,000
One thing that you really need to remember in keywords argument.

352
00:17:45,000 --> 00:17:51,000
All the keys or all the parameters will be in the form of key value pair.

353
00:17:51,000 --> 00:17:54,000
Okay, again, I'm repeating it in keyword arguments.

354
00:17:54,000 --> 00:18:00,000
All the parameters will be in the form of key value arguments like key value pairs.

355
00:18:00,000 --> 00:18:04,000
Now you know if it is in the form of key value pairs.

356
00:18:04,000 --> 00:18:08,000
That basically means you'll be able to access this like how we access dictionaries.

357
00:18:08,000 --> 00:18:22,000
So I may go ahead and write uh for key comma value in k w a r g s dot items right dot items right.

358
00:18:22,000 --> 00:18:27,000
If I go ahead and execute this now, what will happen if I go ahead and print it so it will be nothing

359
00:18:27,000 --> 00:18:28,000
but f.

360
00:18:31,000 --> 00:18:36,000
Key colon value.

361
00:18:36,000 --> 00:18:37,000
Right.

362
00:18:37,000 --> 00:18:39,000
So I'll just go ahead and execute this.

363
00:18:39,000 --> 00:18:41,000
Now how do we provide a keyword argument.

364
00:18:41,000 --> 00:18:42,000
It's very simple.

365
00:18:42,000 --> 00:18:46,000
Let's say I want to just go ahead and print, uh, these details.

366
00:18:46,000 --> 00:18:49,000
Let's say my first parameter is nothing but name.

367
00:18:49,000 --> 00:18:50,000
Okay.

368
00:18:50,000 --> 00:18:55,000
I have not defined it anywhere, but but during runtime I'm just giving name.

369
00:18:55,000 --> 00:19:01,000
Chris, age 32 and let's say, uh, city or country.

370
00:19:01,000 --> 00:19:02,000
I'll go ahead and write.

371
00:19:02,000 --> 00:19:04,000
Country is nothing but India.

372
00:19:04,000 --> 00:19:12,000
Okay, now, if I go ahead and print all these details so directly, see in if all my values is in the

373
00:19:12,000 --> 00:19:18,000
form of key value pair, where I'm using a key name, I'm using a value name key value key value.

374
00:19:18,000 --> 00:19:25,000
So all these parameters will be referenced by star star kW args okay.

375
00:19:25,000 --> 00:19:27,000
Star star kW args.

376
00:19:28,000 --> 00:19:34,000
If all the parameters are just written like this where it does not have any key name, then this basically

377
00:19:34,000 --> 00:19:36,000
becomes a positional argument.

378
00:19:36,000 --> 00:19:40,000
Okay, now let's combine both of them and let's see how things work right now.

379
00:19:40,000 --> 00:19:41,000
Okay.

380
00:19:41,000 --> 00:19:43,000
So I will just go ahead and write definition.

381
00:19:44,000 --> 00:19:44,000
Okay.

382
00:19:44,000 --> 00:19:47,000
And how do I specify my positional key argument.

383
00:19:47,000 --> 00:19:49,000
Nothing but star args.

384
00:19:49,000 --> 00:19:51,000
So this will be my first parameter.

385
00:19:51,000 --> 00:19:52,000
This will be my second parameter.

386
00:19:52,000 --> 00:19:55,000
Now in my first parameter I will go ahead and write.

387
00:19:55,000 --> 00:19:57,000
And let me just go ahead and display this.

388
00:19:57,000 --> 00:20:01,000
And for ARGs I'm just going to display this values.

389
00:20:01,000 --> 00:20:02,000
Okay.

390
00:20:02,000 --> 00:20:05,000
Let's say I'll not take numbers because I can display anything right.

391
00:20:05,000 --> 00:20:09,000
For val in args print Val okay.

392
00:20:09,000 --> 00:20:15,000
Uh and here also what I'm going to do just to make it much more better, I'm going to use a f string.

393
00:20:15,000 --> 00:20:19,000
And here I'm just going to use this indication.

394
00:20:20,000 --> 00:20:22,000
And I'm going to right over here.

395
00:20:22,000 --> 00:20:22,000
Right.

396
00:20:22,000 --> 00:20:27,000
So what I have done over here for val in args print val okay.

397
00:20:27,000 --> 00:20:31,000
For key comma value in kW a args dot items key.

398
00:20:31,000 --> 00:20:33,000
We are just going to print this.

399
00:20:33,000 --> 00:20:40,000
Now the best way is that I will go ahead and write over here something like positional argument argument

400
00:20:40,000 --> 00:20:41,000
okay.

401
00:20:41,000 --> 00:20:42,000
And this will be my value.

402
00:20:42,000 --> 00:20:42,000
Now see?

403
00:20:42,000 --> 00:20:44,000
Now I'm using both of them.

404
00:20:44,000 --> 00:20:44,000
Right.

405
00:20:44,000 --> 00:20:47,000
Now how this function is able to identify.

406
00:20:47,000 --> 00:20:47,000
Right.

407
00:20:47,000 --> 00:20:50,000
Let's say I'm giving print underscore detail.

408
00:20:50,000 --> 00:20:53,000
Let's say I give my positional arguments like 12345 okay.

409
00:20:53,000 --> 00:20:56,000
And here I will go ahead and write Krish okay.

410
00:20:56,000 --> 00:21:00,000
So this basically becomes my positional all the positional arguments.

411
00:21:00,000 --> 00:21:07,000
Uh, and between them I will just go ahead and give this keyword argument, let's say go ahead and give

412
00:21:07,000 --> 00:21:09,000
it anywhere, anywhere that you want to give.

413
00:21:09,000 --> 00:21:10,000
Okay.

414
00:21:10,000 --> 00:21:14,000
Now out of all these parameters, it will be able to identify okay.

415
00:21:14,000 --> 00:21:17,000
Let's see what is the error that is probably coming over here.

416
00:21:18,000 --> 00:21:21,000
Positional argument cannot uh, appear after keyword argument.

417
00:21:21,000 --> 00:21:22,000
See this is the error.

418
00:21:23,000 --> 00:21:26,000
Now the main problem over here when we write like this right.

419
00:21:26,000 --> 00:21:31,000
First of all always remember we need to specify all my positional key arguments.

420
00:21:31,000 --> 00:21:32,000
Now I will go ahead and write my keyword argument.

421
00:21:32,000 --> 00:21:38,000
Now if I go ahead and execute the details see initially first argument is positional argument second

422
00:21:38,000 --> 00:21:41,000
third fourth till here and this.

423
00:21:41,000 --> 00:21:44,000
All that you'll be able to see is my keyword argument.

424
00:21:44,000 --> 00:21:50,000
So this is very much important to understand the differences between positional and keyword argument.

425
00:21:50,000 --> 00:21:55,000
In keyword argument you have all the parameters in key value pairs, like how we have specified over

426
00:21:55,000 --> 00:21:57,000
here in positional.

427
00:21:57,000 --> 00:22:02,000
You just have uh, something like one, two, three, four, five with respect to only the names that

428
00:22:02,000 --> 00:22:04,000
will be there will not be assigning any key names.

429
00:22:04,000 --> 00:22:05,000
Right.

430
00:22:05,000 --> 00:22:10,000
So this is the most important thing with respect to keyword and positional arguments.

431
00:22:10,000 --> 00:22:12,000
I hope you were able to understand.

432
00:22:12,000 --> 00:22:14,000
I hope you are able to understand the difference between them.

433
00:22:14,000 --> 00:22:19,000
And it is very much important if you know this, because next, uh, in the upcoming session you'll

434
00:22:19,000 --> 00:22:23,000
be seeing, I'll be defining functions where I'll be having multiple parameters over there.

435
00:22:23,000 --> 00:22:26,000
And then we will also be seeing that, okay.

436
00:22:26,000 --> 00:22:32,000
Now, uh, let's talk about the last topic for this video that is called as return statement.

437
00:22:32,000 --> 00:22:34,000
And I hope I've already spoken about it.

438
00:22:34,000 --> 00:22:43,000
In return statement, our function returns something right after the entire statement is executed.

439
00:22:43,000 --> 00:22:43,000
Right.

440
00:22:43,000 --> 00:22:44,000
So let me just go ahead and do it.

441
00:22:44,000 --> 00:22:47,000
So here I am going to create my multiply function.

442
00:22:48,000 --> 00:22:49,000
This will be a comma b.

443
00:22:49,000 --> 00:22:53,000
And here I'll just go ahead and return a multiplied by b.

444
00:22:53,000 --> 00:22:54,000
Right.

445
00:22:54,000 --> 00:22:59,000
So here we are returning some value after the function is getting executed now in order to execute it.

446
00:22:59,000 --> 00:23:02,000
So I will go go ahead and define my multiply function.

447
00:23:02,000 --> 00:23:04,000
Let's go ahead and write two comma three.

448
00:23:04,000 --> 00:23:09,000
And finally I get my output so functions can return multiple values.

449
00:23:09,000 --> 00:23:13,000
Also let's see whether this function will be able to return multiple value or not.

450
00:23:13,000 --> 00:23:13,000
Right.

451
00:23:13,000 --> 00:23:16,000
So let's say I will write c is equal to uh.

452
00:23:16,000 --> 00:23:20,000
Or let me just define this function once again okay.

453
00:23:20,000 --> 00:23:22,000
And let me execute it over here.

454
00:23:22,000 --> 00:23:28,000
So here I will say hey return a comma B comma a.

455
00:23:28,000 --> 00:23:28,000
Okay.

456
00:23:28,000 --> 00:23:31,000
Let's see whether we'll be able to return this.

457
00:23:31,000 --> 00:23:35,000
So in Python a function can also return multiple values.

458
00:23:35,000 --> 00:23:38,000
So here we are returning a comma b comma a a comma b is nothing.

459
00:23:38,000 --> 00:23:40,000
But uh let's say we two comma three have given.

460
00:23:40,000 --> 00:23:43,000
So two comma three is six multiply.

461
00:23:43,000 --> 00:23:45,000
When we are doing it is six and a value is two.

462
00:23:45,000 --> 00:23:48,000
So we can also return multiple statements.

463
00:23:48,000 --> 00:23:50,000
Uh um sorry multiple parameters.

464
00:23:51,000 --> 00:23:58,000
Uh multiple multiple parameters uh, from a function.

465
00:23:58,000 --> 00:23:58,000
Okay.

466
00:23:58,000 --> 00:24:00,000
And that is what we basically use.

467
00:24:00,000 --> 00:24:02,000
We need to use this return variable.

468
00:24:03,000 --> 00:24:05,000
So I hope you are able to understand this.

469
00:24:05,000 --> 00:24:06,000
This was it for my side.

470
00:24:06,000 --> 00:24:08,000
This was all about functions.

471
00:24:08,000 --> 00:24:12,000
In the upcoming session we are going to learn more many amazing things about function.

472
00:24:12,000 --> 00:24:15,000
Uh, there are many things like lambda function, nested function, high order function.

473
00:24:15,000 --> 00:24:17,000
We will be discussing about them.

474
00:24:17,000 --> 00:24:18,000
So yes, this was it.

475
00:24:18,000 --> 00:24:21,000
I will see you all in the next video.

476
00:24:21,000 --> 00:24:21,000
Thank you.

