WEBVTT

00:00.320 --> 00:01.100
Hello guys.

00:01.100 --> 00:04.220
So we are going to continue the discussion with respect to Python.

00:04.220 --> 00:09.500
And in this video we are going to discuss about the most important module that is called as functions.

00:09.500 --> 00:11.600
So what is the entire video outline?

00:11.600 --> 00:15.140
In this video I will be discussing about what exactly is functions.

00:15.140 --> 00:16.790
Why do we require functions?

00:16.820 --> 00:21.350
Along with that, we will also be seeing about uh, calling a function defining a function.

00:21.350 --> 00:22.190
How do we define it?

00:22.220 --> 00:23.630
What is the syntax of it.

00:23.630 --> 00:28.580
Then along with that we will be discussing about functions parameter default parameters.

00:28.610 --> 00:30.710
Then what is variable length arguments.

00:30.740 --> 00:30.980
You know.

00:31.010 --> 00:36.710
So there are some very important arguments like positional argument and keyword argument will be discussing

00:36.710 --> 00:37.460
about that.

00:37.490 --> 00:41.210
Then we will also be discussing about return statement.

00:41.210 --> 00:46.130
So we will be covering each and every thing uh, with the help of again code with the help of Python.

00:46.190 --> 00:46.520
Yeah.

00:46.550 --> 00:49.940
Each and every thing will try to write it down with multiple examples.

00:49.940 --> 00:55.610
And I'll be making sure that you understand this, because this is one of the most important thing,

00:55.610 --> 01:00.270
because whenever we are writing any data science projects or Python projects, we will be definitely

01:00.270 --> 01:01.800
using a lot of functions.

01:01.800 --> 01:04.980
So first of all, let's go ahead and define the function.

01:05.010 --> 01:07.530
A function is a block of code.

01:07.560 --> 01:08.190
Okay.

01:08.220 --> 01:09.120
Again I'm repeating it.

01:09.150 --> 01:13.350
A function is a block of code that performs a specific task.

01:13.380 --> 01:19.530
A functions help in organizing code, reusing code, and improving readability.

01:19.560 --> 01:23.580
Okay, so it is a block of code that performs a specific task.

01:23.610 --> 01:27.360
It helps in organizing code, reusing code, and improving readability.

01:27.510 --> 01:31.290
One of the best syntax if you really want to check it out right.

01:31.320 --> 01:32.790
So this is the syntax.

01:32.790 --> 01:35.400
So here I'm just going to give you the syntax.

01:35.400 --> 01:37.350
This function is an empty function.

01:37.350 --> 01:41.370
I've just written it for the for just to make you understand.

01:41.370 --> 01:44.550
So first of all a function starts with a definition keyword.

01:44.580 --> 01:46.980
Then you have the function name.

01:46.980 --> 01:49.710
And if any parameters that you are defining.

01:49.710 --> 01:51.780
So we have to define the parameters.

01:51.900 --> 01:53.760
This is docstring.

01:54.000 --> 02:00.400
Docstring is just to use to uh you know write some kind of comments, what the specific function does

02:00.400 --> 02:04.120
so that any De developer will be able to understand it.

02:04.390 --> 02:07.180
Along with that, we will go ahead and write our function body.

02:07.210 --> 02:11.410
Function body is more about all the code that we are going to use inside the function.

02:11.410 --> 02:14.110
And then finally we return some kind of value.

02:14.140 --> 02:14.620
Okay.

02:14.650 --> 02:17.890
It is not necessary that a return should be there.

02:17.890 --> 02:22.300
Some of the functions may not have return value, but some of the functions will definitely have a lot

02:22.330 --> 02:23.380
of return value.

02:23.410 --> 02:24.250
Okay.

02:24.490 --> 02:27.850
So uh this is the basic syntax.

02:27.850 --> 02:33.010
Now let me just go ahead and tell or talk about why do we require function.

02:33.040 --> 02:33.250
Okay.

02:33.280 --> 02:34.840
Why functions.

02:34.840 --> 02:38.080
This is important for everybody to understand.

02:38.110 --> 02:41.020
Let's say I am creating a number variable.

02:41.020 --> 02:47.380
And I go ahead and write a code which will be able to check whether a number is even or odd.

02:47.380 --> 02:53.830
So suppose if I go ahead and write if num modulus two or percentile two is double equal to zero, then

02:53.830 --> 02:58.230
obviously I'll say hey print the number is even, right?

02:58.290 --> 02:59.910
So I'm just going to write.

02:59.910 --> 03:01.470
The number is even else.

03:01.470 --> 03:06.060
What I usually do is that in this I will go ahead and print and write.

03:06.150 --> 03:10.170
The number is odd right.

03:10.290 --> 03:14.010
So here what exactly is basically happening.

03:14.040 --> 03:16.560
We are just going to check whether a number is even or not.

03:16.590 --> 03:21.120
And obviously if I go ahead and execute this condition will be true because the number is even.

03:21.120 --> 03:22.500
And I'm going to get the answer.

03:22.500 --> 03:23.250
The number is even.

03:23.280 --> 03:23.850
Okay.

03:24.150 --> 03:30.540
Now let's say in my project I want to write this piece of code, and I need to reuse this piece of code

03:30.540 --> 03:35.580
in multiple places, because in multiple places I'm going to check whether a number is odd or even.

03:35.610 --> 03:40.860
Right now, in this case, what I have to do, I have to copy this same code and use it in multiple

03:40.860 --> 03:43.200
files instead of this.

03:43.200 --> 03:47.880
A better way of reusing the entire code will be with the help of functions.

03:47.880 --> 03:48.150
Now what?

03:48.150 --> 03:51.300
I will do this entire code I will write inside a function.

03:51.540 --> 03:56.050
Now the best way to write is that let's say I will go ahead and create my definition keyword.

03:56.050 --> 04:00.040
I will say, hey, my function name is even or odd, okay?

04:00.160 --> 04:04.060
And this will specifically take a parameter which is called as number.

04:04.150 --> 04:07.960
And now I will go ahead and write my condition inside this.

04:07.960 --> 04:08.260
Right.

04:08.290 --> 04:14.590
So as soon as I go ahead and press enter, that basically means I'm inside my function.

04:14.620 --> 04:14.800
Right.

04:14.830 --> 04:18.070
So automatically the indentation goes inside this function block.

04:18.070 --> 04:18.700
Right.

04:19.390 --> 04:23.080
Now the first thing is that I can go ahead and write my docstring.

04:23.110 --> 04:33.820
The docstring will be like, hey, this function performs um finds even or odd, okay, even or odd.

04:33.820 --> 04:36.280
So this is what I'm specifically writing over here.

04:36.340 --> 04:37.930
So this becomes my docstring.

04:37.930 --> 04:40.930
It is not compulsory that you really need to write a docstring.

04:40.930 --> 04:43.270
You can leave it completely empty.

04:43.720 --> 04:48.490
Uh, and you may also not even write any of these things, but it is a good practice that we should

04:48.490 --> 04:51.190
definitely write some information about the function itself.

04:51.820 --> 04:55.310
Uh, now I will go ahead and write my code inside this.

04:55.310 --> 04:56.390
Now I will go ahead and write.

04:56.390 --> 05:01.340
If num num is nothing but the same, uh, parameter that I'm actually getting.

05:01.340 --> 05:02.810
And this is basically my parameter.

05:02.810 --> 05:16.010
If num percentile two is double equal to zero, I will go ahead and print the the the number is even

05:16.070 --> 05:20.330
or I will go ahead and write else print.

05:23.000 --> 05:25.490
The number is odd right.

05:25.490 --> 05:28.550
So here you can see I have defined this entire function.

05:28.550 --> 05:32.060
Now I'll just go ahead and press it and execute it right.

05:32.060 --> 05:36.140
So as soon as I execute it I have actually created my first function.

05:36.170 --> 05:36.500
Right.

05:36.530 --> 05:37.610
And this is amazing.

05:37.610 --> 05:41.870
And if you have also created it, always make sure the indentation is managed.

05:41.870 --> 05:45.260
If the indentation is right then everything is going to work fine.

05:45.290 --> 05:45.740
Okay.

05:45.770 --> 05:48.530
Let's say if I miss out the indentation I execute it.

05:48.530 --> 05:49.700
I will be getting an error.

05:49.700 --> 05:53.010
It will be saying hey, expected an and intended block after the if statement.

05:53.010 --> 05:55.560
And this is what we have actually done.

05:56.490 --> 05:58.950
Okay, so I'll just control Z.

05:58.980 --> 05:59.220
Yeah.

05:59.250 --> 06:00.270
Now we are fine.

06:00.270 --> 06:02.490
I'll go ahead and create my function even or odd.

06:02.520 --> 06:04.830
Now in order to call this function.

06:04.830 --> 06:11.460
So let's call this function now wherever I want to use this code to find even or odd, I will just call

06:11.460 --> 06:13.140
this function okay.

06:13.170 --> 06:17.640
In order to call this function just go ahead and call the function name.

06:17.640 --> 06:20.520
And here you just need to provide your parameter.

06:20.550 --> 06:21.060
Right.

06:21.060 --> 06:24.930
So let's say the number parameter that I'm giving I want to give it as 24.

06:24.960 --> 06:30.150
Now if I go ahead and execute it here you can see that automatically it is printing the number is even.

06:30.150 --> 06:33.420
Because as soon as I give the parameter it went over here.

06:33.420 --> 06:35.160
It went and checked all this condition.

06:35.160 --> 06:37.830
Whichever is true, it printed it right.

06:38.130 --> 06:42.690
A very simple way of creating a function and calling a function.

06:42.690 --> 06:44.310
And why do we require a function?

06:44.310 --> 06:46.560
Because every way we cannot write the code.

06:46.560 --> 06:48.390
We need to reuse this kind of code.

06:48.390 --> 06:53.820
So whenever you think okay, I have some set of code block which I really need to reuse it.

06:53.820 --> 06:59.160
I will try to create that entire thing inside a function itself and I'll reuse it.

06:59.160 --> 06:59.430
Right.

06:59.460 --> 07:04.470
So through this, the most important thing will be that it helps in organizing code, reusing code,

07:04.470 --> 07:07.110
and improving readability, improving readability.

07:07.140 --> 07:07.530
Why?

07:07.560 --> 07:12.390
Because we are also writing some amazing docstring over here so that we'll be able to understand, because

07:12.390 --> 07:16.410
in a company, many people will work, many people will write different, different code over there.

07:16.410 --> 07:17.940
Multiple modules will be built.

07:17.970 --> 07:18.510
Okay.

07:18.540 --> 07:22.770
So this was a basic example with respect to function.

07:22.770 --> 07:26.850
I have also spoken about a parameter like what exactly is a parameter?

07:26.850 --> 07:28.650
How do you give a parameter in this?

07:29.550 --> 07:33.420
Now there may be scenario that I may also have multiple parameters.

07:33.420 --> 07:35.580
So let's work with multiple parameter.

07:35.580 --> 07:43.050
So here I will go ahead and write function with multiple parameters okay.

07:45.060 --> 07:48.690
And parameters you can give integer string whatever things you require.

07:48.690 --> 07:50.280
So I will go ahead and write definition.

07:50.310 --> 07:56.730
And let's say I want to go ahead and create a add function to add two numbers.

07:56.730 --> 07:59.790
So I will go ahead and write definition, add a comma b.

07:59.790 --> 08:04.200
And let's say I go ahead and write my docstring again not compulsory.

08:04.200 --> 08:06.000
I can also leave it like this.

08:06.270 --> 08:06.510
Okay.

08:06.510 --> 08:07.620
Just to show it to you.

08:07.620 --> 08:09.090
That is the reason I'm writing.

08:09.360 --> 08:09.720
Okay.

08:09.750 --> 08:11.310
So I will go back over here.

08:11.310 --> 08:11.970
Press enter.

08:11.970 --> 08:15.150
So I'm inside this particular code block.

08:15.210 --> 08:18.960
Now I know that I have to add two variables right.

08:18.990 --> 08:19.830
So I will create.

08:19.860 --> 08:24.210
One way is that I will create a variable c a plus b okay.

08:24.210 --> 08:30.840
And then I can return this c output from that particular function okay.

08:30.870 --> 08:34.560
Return c plus c which is nothing but a plus b.

08:34.710 --> 08:37.020
Whatever sum is there, we are just going to return it.

08:37.020 --> 08:39.000
A better way of writing the code.

08:39.030 --> 08:43.320
Instead of writing C, I can directly write return a plus B, right?

08:43.350 --> 08:44.520
So here what we are doing.

08:44.550 --> 08:47.590
We are just returning the sum of A and B.

08:47.920 --> 08:52.690
Now all I have to do is that create a variable and add.

08:53.230 --> 08:54.670
Call this add function.

08:54.670 --> 08:56.650
Here I'm going to give two comma four.

08:56.680 --> 08:58.150
Now what is going to get.

08:58.180 --> 09:00.250
What value result is going to get.

09:00.850 --> 09:05.170
As soon as we call this function two comma four it will just return two plus four.

09:05.200 --> 09:08.980
Whatever will be the result like six it will be stored over here.

09:09.010 --> 09:16.180
Now if I go ahead and print the result here, you'll be able to see that I'm able to get the six value.

09:16.210 --> 09:20.380
So here you can have any number of parameters and code.

09:20.380 --> 09:21.670
Whatever things you are writing.

09:21.670 --> 09:24.850
You can basically use this parameter and write any code that you want.

09:24.880 --> 09:25.480
Okay.

09:25.630 --> 09:29.410
So uh, it is up to you what kind of function that you are building.

09:29.410 --> 09:34.360
And as we go ahead with multiple examples, if we see in the future and in the upcoming videos, we'll

09:34.390 --> 09:36.190
be writing very complex functions.

09:36.190 --> 09:39.430
There is there is something called as decorators lambda function.

09:39.430 --> 09:41.440
Many things will be probably coming one by one.

09:41.440 --> 09:42.490
We will be learning first.

09:42.520 --> 09:43.870
We will start with basics.

09:43.870 --> 09:49.280
Then slowly, slowly we'll be building the blocks with respect to the learning and then we will be continuing

09:49.280 --> 09:49.640
on.

09:49.670 --> 09:55.490
Okay, now let me just go ahead and show you and talk about one very important thing, which is called

09:55.490 --> 09:57.200
as default parameters.

09:57.230 --> 10:01.490
We can also provide default parameters within our function okay.

10:01.520 --> 10:03.710
Now what exactly is default parameters.

10:04.700 --> 10:07.400
Let's say I create a function okay.

10:07.430 --> 10:10.730
I create a function saying as definition greed.

10:10.760 --> 10:11.360
Okay.

10:11.660 --> 10:12.860
Definition greed.

10:12.860 --> 10:14.930
This function is responsible.

10:14.930 --> 10:18.680
Uh, let's say I give a name over here, right?

10:18.710 --> 10:20.630
Let's say one parameter is name.

10:20.660 --> 10:21.200
Okay.

10:21.380 --> 10:23.450
And here I'm just going to write.

10:23.450 --> 10:24.230
Print.

10:25.250 --> 10:25.820
Okay.

10:26.810 --> 10:29.720
Uh, I'll use the f string and say that okay.

10:29.750 --> 10:34.220
I want to probably, uh, write some information.

10:34.220 --> 10:37.280
Let's say I want to say hello.

10:37.310 --> 10:38.330
Hello.

10:39.080 --> 10:40.760
Whatever the person name is.

10:40.790 --> 10:41.360
Okay.

10:41.390 --> 10:43.450
So I'm going to just go ahead and print this.

10:43.480 --> 10:43.720
Okay.

10:43.750 --> 10:45.670
And this is what is my definition of greed.

10:45.700 --> 10:48.370
Greed is just more like a welcoming someone.

10:48.400 --> 10:49.090
Okay.

10:49.120 --> 10:50.290
Welcoming someone.

10:50.320 --> 10:53.470
Now, what I will do is that I will just go ahead.

10:54.670 --> 10:56.620
Just go ahead and call this function.

10:56.620 --> 10:58.360
So I will go ahead and write, greet.

10:58.360 --> 11:01.240
And let me say that Krish has entered somewhere.

11:01.240 --> 11:05.770
So I will just give the Krish parameter like, let's say you are entering a restaurant and as soon as

11:05.770 --> 11:12.010
you write Krish over there in one of the application and suddenly I will get a message saying that.

11:12.040 --> 11:12.970
Hello Krish.

11:13.000 --> 11:13.570
Okay.

11:13.600 --> 11:15.880
Or welcome something like this.

11:15.880 --> 11:19.720
Welcome to the Paradise.

11:19.720 --> 11:21.910
Let's say this is my message.

11:21.910 --> 11:22.540
Hello, Krish.

11:22.540 --> 11:23.500
Welcome to the Paradise.

11:23.500 --> 11:28.150
So as soon as I give this parameter automatically, this will get replaced over here.

11:28.180 --> 11:28.750
Okay.

11:29.230 --> 11:33.370
Now I may also give one parameter.

11:33.370 --> 11:36.460
I may also give some parameters with a default value.

11:36.490 --> 11:36.970
Okay.

11:37.000 --> 11:38.080
With a default value.

11:38.080 --> 11:39.430
Now what does that particular mean?

11:39.460 --> 11:40.000
Okay.

11:40.360 --> 11:45.630
Let's say I just go over here and this time I don't give Krish.

11:45.660 --> 11:46.020
Okay.

11:46.050 --> 11:49.140
I'll just try to execute this without giving any parameter.

11:49.230 --> 11:54.330
So here you can see I will be getting an error greet missing one requirement positional argument.

11:54.360 --> 11:54.600
Okay.

11:54.630 --> 11:56.580
We will talk about what exactly is positional argument.

11:56.580 --> 11:57.840
More about it.

11:57.840 --> 12:02.940
But here you can see that I have given this particular name parameter over here, but I have not given

12:02.940 --> 12:04.230
any parameter when I'm calling it.

12:04.230 --> 12:06.330
And that is the reason I'm getting this one.

12:06.330 --> 12:08.040
Missing one required positional argument.

12:08.070 --> 12:08.610
Okay.

12:08.760 --> 12:14.880
Now in order to solve this problem, what I can do, I will say since I'm not giving the name, I may

12:14.880 --> 12:17.910
give a default value to the name.

12:17.910 --> 12:21.240
Let's say if I'm not giving it over here, then what will happen?

12:21.270 --> 12:21.480
It will.

12:21.510 --> 12:26.880
First of all, go and see whether the greet name is equal to guest is given or not.

12:27.510 --> 12:32.940
Now, if I go ahead and execute this, see, I'm not giving any parameter but the default parameter,

12:32.940 --> 12:34.170
it will take it as guest.

12:34.200 --> 12:34.740
Okay.

12:34.740 --> 12:37.080
So if I go ahead and execute it here you can see.

12:37.110 --> 12:37.770
Hello guest.

12:37.770 --> 12:39.150
Welcome to the Paradise.

12:39.180 --> 12:41.550
Let's say if I go ahead and give the name.

12:42.000 --> 12:42.300
Okay.

12:42.330 --> 12:46.740
Over here, let's say the guest is not interested to give the name, so by default it will take it as

12:46.740 --> 12:47.250
guest.

12:47.250 --> 12:51.570
But if I'm giving my name, it will just replace the guest will get replaced with Krish.

12:51.600 --> 12:51.960
Okay.

12:51.990 --> 12:57.180
So this is some good example with respect to the default parameters.

12:57.180 --> 13:00.090
And this is how you can also assign default parameters.

13:00.300 --> 13:06.090
Now we are going to discuss about the main topic which you will be seeing in function.

13:06.090 --> 13:14.940
That is nothing but variable length length arguments okay.

13:15.270 --> 13:19.890
Now in the variable length arguments here we are going to discuss about two things.

13:19.890 --> 13:24.180
One is positional and keyword argument.

13:24.210 --> 13:24.840
Okay.

13:25.020 --> 13:28.020
Positional and keyword argument okay.

13:28.140 --> 13:32.940
Keyword arguments okay.

13:33.510 --> 13:37.800
Now let me do let me tell you one very important thing.

13:37.800 --> 13:41.740
Let's say that I have in a function many, many parameters as such.

13:41.770 --> 13:42.370
Okay.

13:42.430 --> 13:52.360
And let me just define one simple function that is called as definition print underscore numbers okay.

13:52.600 --> 13:58.000
And here inside this let's say I have like this okay.

13:58.000 --> 13:58.690
Number one.

13:58.690 --> 13:59.620
Number two.

13:59.650 --> 14:00.580
Number three.

14:00.610 --> 14:01.690
Number four.

14:01.690 --> 14:02.650
Number five.

14:02.680 --> 14:04.360
Like this I have many, many parameters.

14:04.360 --> 14:05.320
In short okay.

14:05.500 --> 14:12.490
It's just not one single parameter I can I am basically having many, many, many many parameters.

14:12.520 --> 14:13.000
Okay.

14:13.000 --> 14:17.710
So what I will do instead of just writing all the parameter names, right?

14:17.740 --> 14:23.980
I will use one very simple positional argument which we denote it as star args.

14:24.010 --> 14:24.550
Okay.

14:24.670 --> 14:26.080
Now it is not necessary.

14:26.080 --> 14:27.490
You need to write star args.

14:27.490 --> 14:29.710
I can go ahead and write star crush also.

14:29.740 --> 14:30.400
Okay.

14:30.760 --> 14:32.440
But it is always a good practice.

14:32.470 --> 14:34.600
What is followed throughout the entire world?

14:34.600 --> 14:36.400
The same practice we should also do.

14:36.430 --> 14:39.090
Now In this particular case, I will just show you its stock price.

14:39.120 --> 14:42.390
Then we will go ahead and write with the documentation.

14:42.390 --> 14:47.550
Like what is the best practices argument we specifically use like positional arguments is basically

14:47.550 --> 14:49.980
given by star args.

14:50.010 --> 14:53.160
As I said, it need not be a args.

14:53.190 --> 14:54.270
I can also write Krish.

14:54.300 --> 14:58.380
Okay, now I will go ahead and go ahead inside this particular function.

14:58.830 --> 15:00.930
Now here what I will do.

15:00.930 --> 15:04.410
As you know the star creche will be having multiple parameters.

15:04.410 --> 15:10.410
So what I will do, I will just go ahead and write four numbers in creche.

15:10.440 --> 15:10.920
Okay.

15:10.950 --> 15:12.180
Which is my argument.

15:12.180 --> 15:18.810
I will go ahead and print numbers okay okay I will go ahead and print number okay.

15:18.840 --> 15:20.040
Now see this okay.

15:20.100 --> 15:21.810
So this becomes my function.

15:21.810 --> 15:23.910
Please observe very carefully okay.

15:23.940 --> 15:27.480
Now my print underscore numbers function.

15:27.480 --> 15:33.510
When I'm calling let's say I have one comma two comma 345 comma six comma creche.

15:33.540 --> 15:35.220
It can be anything okay.

15:35.260 --> 15:37.570
So these are all the parameters that I have.

15:37.600 --> 15:39.790
You can see it is a set of parameters.

15:39.790 --> 15:43.330
And this parameters are basically called as positional arguments.

15:43.360 --> 15:43.600
Okay.

15:43.630 --> 15:46.120
Positional arguments one after the other.

15:46.150 --> 15:47.710
Now if I go ahead and execute.

15:47.740 --> 15:48.940
Now see the magic.

15:48.970 --> 15:53.230
This all the parameters will be referenced by Star Crush.

15:53.260 --> 15:53.440
Okay.

15:53.470 --> 15:57.730
So crush will be a variable which will be referring all this particular positional arguments.

15:57.760 --> 16:02.680
Now if I go ahead and execute it now clearly here you can see for all the numbers it is being able to

16:02.710 --> 16:03.850
iterate through this.

16:03.880 --> 16:05.020
Right 1234.

16:05.020 --> 16:07.360
And it is displaying it something like this okay.

16:07.390 --> 16:09.100
Because here I just used one.

16:09.100 --> 16:13.540
So this star crush is basically referring to all the positional arguments right.

16:13.570 --> 16:16.990
Positional arguments basically means all the arguments that is given over here.

16:17.020 --> 16:17.620
Okay.

16:17.650 --> 16:24.340
Now, as I always said, the best practice would be I will go ahead and write this and I will say args.

16:24.370 --> 16:24.550
Okay.

16:24.550 --> 16:28.810
So args is a kind of argument positional argument that we basically use.

16:28.840 --> 16:29.020
Okay.

16:29.050 --> 16:32.470
So here I'm going to write positional arguments.

16:33.320 --> 16:33.950
Okay.

16:34.340 --> 16:37.670
White is important because I may have many number of arguments over there.

16:37.700 --> 16:40.790
Okay, so I may directly use this specific thing.

16:40.820 --> 16:41.360
Okay.

16:41.390 --> 16:46.460
Now the other thing will be that okay, this is fine if I go ahead and execute it.

16:46.460 --> 16:50.990
And if I execute the same thing okay, I will be able to get the same answer.

16:50.990 --> 16:51.410
Fine.

16:51.410 --> 16:51.800
Perfect.

16:51.800 --> 16:53.690
123456 crash.

16:53.780 --> 17:00.410
Now there is also one more important function which is called as keyword argument.

17:02.120 --> 17:04.370
Okay, now what exactly is keyword argument?

17:04.400 --> 17:09.080
Okay, uh, let me just go ahead and create one more function.

17:09.110 --> 17:09.650
Okay.

17:09.740 --> 17:16.490
Let's say I will go ahead and write uh, print uh sorry definition print underscore detail.

17:16.910 --> 17:22.160
Now how it is different from positional argument you'll be able to understand keyword argument is given

17:22.160 --> 17:23.420
by double star.

17:24.110 --> 17:26.330
And you can write any parameter that you have.

17:26.330 --> 17:34.110
So usually the best practice that is basically used is k w a r g s k w basically means keyword argument,

17:34.140 --> 17:34.650
right?

17:34.680 --> 17:37.440
ARGs is a simple positional argument.

17:37.980 --> 17:40.770
Now inside this, let me do one thing.

17:41.760 --> 17:45.780
One thing that you really need to remember in keyword argument.

17:45.840 --> 17:51.540
All the keys or all the parameters will be in the form of key value pair.

17:51.600 --> 17:52.320
Okay.

17:52.350 --> 17:54.750
Again, I'm repeating it in keyword arguments.

17:54.750 --> 18:00.510
All the parameters will be in the form of key value arguments like key value pairs.

18:00.690 --> 18:04.230
Now you know if it is in the form of key value pairs.

18:04.260 --> 18:08.550
That basically means you'll be able to access this like how we access dictionaries.

18:08.550 --> 18:20.280
So I may go ahead and write uh for key comma value in k w a args dot items.

18:20.280 --> 18:21.000
Right.

18:21.180 --> 18:22.860
Dot items right.

18:22.890 --> 18:26.880
If I go ahead and execute this now, what will happen if I go ahead and print it.

18:26.880 --> 18:28.920
So it will be nothing but f.

18:30.950 --> 18:36.920
Key colon value.

18:36.950 --> 18:37.610
Right.

18:37.610 --> 18:39.380
So I'll just go ahead and execute this.

18:39.380 --> 18:41.630
Now how do we provide a keyword argument.

18:41.630 --> 18:42.440
It's very simple.

18:42.440 --> 18:46.790
Let's say I want to just go ahead and print out these details.

18:46.790 --> 18:54.050
Let's say my first parameter is nothing but name okay I've not defined it anywhere but but during runtime

18:54.050 --> 18:55.520
I'm just giving name.

18:55.580 --> 19:01.310
Chris, age 32 and let's say uh, city or country.

19:01.310 --> 19:04.400
I'll go ahead and write country is nothing but India.

19:04.910 --> 19:12.590
Okay, now if I go ahead and print all these details so directly, see in if all my values is in the

19:12.590 --> 19:18.770
form of key value pair, where I'm using a key name, I'm using a value name key value key value.

19:18.770 --> 19:25.700
So all these parameters will be referenced by star star kW args okay.

19:25.730 --> 19:28.070
Star star kW args.

19:28.320 --> 19:34.530
If all the parameters are just written like this, where it does not have any key name, then this basically

19:34.530 --> 19:36.240
becomes a positional argument.

19:36.270 --> 19:40.770
Okay, now let's combine both of them and let's see how things work out right now.

19:40.800 --> 19:41.280
Okay.

19:41.280 --> 19:43.890
So I will just go ahead and write definition.

19:44.310 --> 19:44.880
Okay.

19:44.880 --> 19:47.730
And how do I specify my positional key argument.

19:47.760 --> 19:49.620
Nothing but star args.

19:49.620 --> 19:51.180
So this will be my first parameter.

19:51.210 --> 19:52.710
This will be my second parameter.

19:52.740 --> 19:55.710
Now in my first parameter I will go ahead and write.

19:55.740 --> 19:57.630
And let me just go ahead and display this.

19:57.630 --> 20:01.950
And for ARGs I'm just going to display this values.

20:01.980 --> 20:02.520
Okay.

20:02.550 --> 20:05.640
Let's say I will not take numbers because I can display anything right.

20:05.640 --> 20:08.520
For val in args print val.

20:08.550 --> 20:09.090
Okay.

20:09.570 --> 20:15.390
And here also what I'm going to do just to make it much more better I'm going to use a f string.

20:15.540 --> 20:19.500
And here I'm just going to use this indication.

20:20.580 --> 20:22.350
And I'm going to write over here.

20:22.380 --> 20:22.890
Right.

20:22.890 --> 20:27.060
So what I have done over here for val in args print val okay.

20:27.100 --> 20:31.600
for key comma value in k w args dot items key.

20:31.780 --> 20:33.100
We are just going to print this.

20:33.130 --> 20:40.390
Now the best way is that I will go ahead and write over here something like positional argument argument.

20:40.480 --> 20:41.050
Okay.

20:41.170 --> 20:42.340
And this will be my value.

20:42.340 --> 20:44.920
Now see now I'm using both of them right.

20:44.950 --> 20:47.260
Now how this function is able to identify.

20:47.290 --> 20:47.800
Right.

20:47.830 --> 20:50.050
Let's say I'm giving print underscore detail.

20:50.050 --> 20:53.830
Let's say I give my positional arguments like 12345 okay.

20:53.830 --> 20:56.830
And here I will go ahead and write Krish okay.

20:56.830 --> 21:03.040
So this basically becomes my positional all the positional arguments uh, and between them I will just

21:03.040 --> 21:09.430
go ahead and give this keyword argument, let's say go ahead and give it anywhere, anywhere that you

21:09.430 --> 21:09.940
want to give.

21:09.970 --> 21:10.450
Okay.

21:10.480 --> 21:14.980
Now out of all these parameters it will be able to identify okay.

21:14.980 --> 21:18.040
Let's see what is the error that is probably coming over here.

21:18.130 --> 21:21.700
Positional argument cannot appear after keyword argument.

21:21.730 --> 21:23.020
See this is the error.

21:23.590 --> 21:26.750
Now the main problem over here when we write like this, right?

21:26.780 --> 21:31.040
First of all, always remember we need to specify all my positional key arguments.

21:31.070 --> 21:32.930
Now I will go ahead and write my keyword argument.

21:32.960 --> 21:38.510
Now if I go ahead and execute the details see initially first argument is positional argument.

21:38.540 --> 21:40.070
Second third fourth.

21:40.160 --> 21:44.600
Till here and this is all that you will be able to see is my keyword argument.

21:44.600 --> 21:50.420
So this is very much important to understand the differences between positional and keyword argument.

21:50.840 --> 21:55.550
In keyword argument you have all the parameters in key value pairs, like how we have specified over

21:55.550 --> 21:57.050
here in positional.

21:57.050 --> 22:00.680
You just have uh, something like one, two, three, four, five.

22:00.710 --> 22:05.000
With respect to only the names that will be there will not be assigning any key names.

22:05.000 --> 22:05.510
Right.

22:05.510 --> 22:10.370
So this is the most important thing with respect to keyword and positional arguments.

22:10.370 --> 22:12.200
I hope you were able to understand.

22:12.230 --> 22:17.150
I hope you are able to understand the difference between them, and it is very much important if you

22:17.180 --> 22:21.230
know this, because next, uh, in the upcoming session you'll be seeing, I'll be defining functions

22:21.230 --> 22:25.540
where I'll be having multiple parameters over there, and then we will also be seeing that.

22:25.570 --> 22:26.110
Okay.

22:26.170 --> 22:32.860
Now, uh, let's talk about the last topic for this video that is called as return statement, and I

22:32.860 --> 22:34.870
hope I've already spoken about it.

22:34.870 --> 22:43.030
In return statement, our function returns something right after the entire statement is executed.

22:43.060 --> 22:43.360
Right.

22:43.360 --> 22:44.890
So let me just go ahead and do it.

22:44.890 --> 22:48.040
So here I am going to create my multiply function.

22:48.160 --> 22:49.390
This will be a comma b.

22:49.720 --> 22:53.500
And here I'll just go ahead and return a multiplied by b.

22:53.530 --> 22:54.040
Right.

22:54.040 --> 22:59.560
So here we are returning some value after the function is getting executed now in order to execute it.

22:59.560 --> 23:02.650
So I will go go ahead and define my multiply function.

23:02.650 --> 23:04.450
Let's go ahead and write two comma three.

23:04.540 --> 23:06.520
And finally I get my output.

23:06.520 --> 23:09.910
So functions can return multiple values.

23:09.910 --> 23:13.570
Also let's see whether this function will be able to return multiple value or not.

23:13.630 --> 23:13.900
Right.

23:13.930 --> 23:16.900
So let's say I will write c is equal to uh.

23:16.930 --> 23:20.140
Or let me just define this function once again okay.

23:20.170 --> 23:22.060
And let me execute it over here.

23:22.060 --> 23:28.430
So here I will say, hey, return a comma B comma a.

23:28.490 --> 23:28.970
Okay.

23:29.000 --> 23:31.340
Let's see whether we'll be able to return this.

23:31.340 --> 23:35.090
So in Python a function can also return multiple values.

23:35.090 --> 23:38.720
So here we are returning a comma b comma a a comma b is nothing.

23:38.720 --> 23:40.940
But let's say we two comma three have given.

23:40.940 --> 23:42.290
So two comma three is six.

23:42.320 --> 23:43.040
Multiply.

23:43.040 --> 23:45.380
When we are doing it is six and a value is two.

23:45.410 --> 23:48.380
So we can also return multiple statements.

23:48.380 --> 23:50.810
Uh sorry multiple parameters.

23:51.050 --> 23:58.160
Uh multiple multiple parameters uh from a function.

23:58.190 --> 23:58.430
Okay.

23:58.460 --> 24:00.170
And that is what we basically use.

24:00.170 --> 24:02.840
We need to use this return variable.

24:03.020 --> 24:05.330
So I hope you are able to understand this.

24:05.330 --> 24:06.620
This was it from my side.

24:06.620 --> 24:08.120
This was all about functions.

24:08.120 --> 24:12.050
In the upcoming session we are going to learn more many amazing things about function.

24:12.260 --> 24:15.860
Uh, there are many things like lambda function, nested function, high order function.

24:15.860 --> 24:17.450
We will be discussing about them.

24:17.450 --> 24:18.890
So yes, this was it.

24:18.890 --> 24:21.200
I will see you all in the next video.

24:21.200 --> 24:21.710
Thank you.
