WEBVTT 00:01.410 --> 00:09.880 Functions are usable piece of code that performs some specific actions that has many built in functions 00:10.400 --> 00:15.590 and we have already seen some of them like bring in but end range. 00:16.710 --> 00:24.370 Besides the building functions we can also create our own functions these are called user defined function 00:26.480 --> 00:32.970 to define a function we use deficit. 00:32.980 --> 00:36.270 Def then we give function names. 00:36.290 --> 00:46.620 For example we can see greetings to Brent. 00:46.730 --> 00:49.150 So this is just a simple function. 00:49.400 --> 00:50.360 We should bring help 00:53.820 --> 00:55.350 to you. 00:55.840 --> 01:06.890 Greetings. 01:10.240 --> 01:11.390 Call a function. 01:11.400 --> 01:14.190 We just simply type the name of the function. 01:14.390 --> 01:14.930 Just say. 01:14.930 --> 01:15.530 Greetings 01:18.970 --> 01:21.980 sorry. 01:30.200 --> 01:32.560 Function can also take arguments 01:36.170 --> 01:38.890 and we define arguments here. 01:39.230 --> 01:40.480 Just read 01:42.830 --> 01:43.920 re 01:51.050 --> 01:54.850 not call a function with arguments. 01:55.180 --> 01:57.940 You need to specify some argument here. 02:04.580 --> 02:05.230 Are you 02:14.550 --> 02:23.430 we can also give default value to the function argument. 02:23.660 --> 02:24.410 You can say 02:37.130 --> 02:37.420 no. 02:37.690 --> 02:45.640 We call a function without any value to the argument. 02:45.990 --> 02:54.090 It will bring good morning or else it will bring the value of the Oregon 03:07.400 --> 03:09.990 let me create a new function. 03:10.980 --> 03:11.920 We'll do some 03:14.680 --> 03:27.610 automatic operations so let's define a variable we say X was the equal to it. 03:30.670 --> 03:36.430 And we said different function wasn't this X Y Z here 03:44.200 --> 03:45.220 and we say 03:49.490 --> 03:54.410 x y z equal to fight. 03:58.670 --> 04:01.420 X was the function 04:05.080 --> 04:18.700 x y so in functions always remember that the variable defined at the top and the very ill defined end 04:18.730 --> 04:21.650 function are two different variables. 04:21.670 --> 04:27.780 It means that this variable is local to this function. 04:27.970 --> 04:35.030 We cannot access this variable outside the function. 04:36.190 --> 04:40.000 So here we can say. 04:40.560 --> 04:43.620 That's what we call a function here. 04:46.720 --> 04:47.600 Then consider bring 04:51.720 --> 04:56.160 so it is the side of the 05:03.550 --> 05:09.630 basically this Brenda statement is referring to this X Y. 05:11.120 --> 05:14.510 And this Brenda statement is a reference to this X was 05:17.300 --> 05:29.110 so the variable defined within a function scoring local variable will be named the name here 05:35.860 --> 05:36.670 run this program. 05:44.510 --> 05:45.410 For the 05:55.830 --> 06:03.070 variable x y z in the function of SPI X what is the outside the function is then is a hundred 06:07.770 --> 06:14.090 if you want to assign a value to the variable defined at the top. 06:14.140 --> 06:18.180 You want to change this when inside the function. 06:18.390 --> 06:24.910 We need to use global a statement like we can say global 06:28.780 --> 06:29.320 global 06:33.840 --> 06:35.020 x y. 06:39.140 --> 06:49.790 Now because of this global statement this X Y Z is referent to this X Y as the means. 06:50.040 --> 06:57.570 Like when you change the value this way you will get changed and at this point the statement will print 06:57.720 --> 07:00.070 x y z outside of the function. 07:00.150 --> 07:03.930 Despite let's see 07:33.270 --> 07:33.580 very 07:41.000 --> 07:47.570 if there are more than one argument and we want to specify the default value of some of them then we 07:47.570 --> 07:49.040 need to name the argument 07:52.660 --> 07:54.060 like here 07:57.140 --> 08:01.770 and say instead of greetings you can save on 08:04.780 --> 08:12.830 a comma B equal to hundred or two hundred 08:16.050 --> 08:16.310 and 08:19.490 --> 08:20.180 is 08:23.600 --> 08:29.590 it is the 08:34.740 --> 08:34.900 B 08:40.160 --> 08:44.820 D or card keyword arguments. 08:44.870 --> 08:46.030 Let's does this 08:57.390 --> 09:00.250 one now. 09:00.260 --> 09:09.230 If you specify what this function with a single in this way you will be assigned to a 09:13.170 --> 09:18.890 if you specify words B second where you will be assigned to B 09:22.970 --> 09:30.300 so the advantage of your arguments is that we don't need to remember the position of the argument like 09:30.300 --> 09:38.240 if we want to assign value to see but not to be. 09:38.400 --> 09:40.170 Then we can call a function like this 09:43.290 --> 09:51.740 we can also define a function with any number of arguments that is arbitrary argument can be done by 09:52.070 --> 09:56.060 fixing one or the argument with Asterix 10:00.050 --> 10:00.970 like we can say 10:04.310 --> 10:05.300 stress me 10:08.890 --> 10:14.980 and we can sit by and say hey 10:22.680 --> 10:32.720 Ron now we can call this function with any number of parameters. 10:42.510 --> 10:51.380 We can also take arbitrary arguments with name by defining an argument would do SRS 10:57.370 --> 10:58.060 numbers 11:02.690 --> 11:09.590 and we can say or name calling my number in 11:12.710 --> 11:15.420 two numbers. 11:16.140 --> 11:16.800 Items 11:20.340 --> 11:21.700 brand name 11:32.850 --> 11:33.200 not. 11:33.210 --> 11:34.920 Call this function. 11:35.160 --> 11:41.370 We need to specify name what value 11:45.420 --> 11:48.080 and again we're going to specify as many name 11:50.760 --> 11:54.230 and as many values as we like. 12:04.300 --> 12:13.380 In functions we also have done a statement which is used to break out of the function and can optionally 12:13.380 --> 12:28.000 return a value let's write a function that compares to EDS and redundant redundant number say buying 12:29.130 --> 12:32.010 the max X or Y 12:35.440 --> 12:37.040 X is greater than y 12:42.670 --> 12:43.040 x 12:50.990 --> 12:51.190 or a 12:54.710 --> 13:01.100 statement the like more X equals equal Y 13:07.290 --> 13:07.650 the 13:12.420 --> 13:12.810 equal 13:15.650 --> 13:16.140 x 13:19.350 --> 13:23.980 return y. 13:24.380 --> 13:32.760 So this is a simple function you can name it as Max 13:38.630 --> 13:46.230 on X all the function rent y in the banks between 5 and 6 13:50.480 --> 13:59.940 bring by Max by. 14:00.350 --> 14:03.340 So this was one simple example of a return statement.