1 00:00:00,990 --> 00:00:05,560 Functions functions functions there are two types of functions. 2 00:00:05,670 --> 00:00:11,790 Bilstein and custom building functions are functions that have already been created by Python authors 3 00:00:12,000 --> 00:00:16,850 and are to use from Python programmers which is always a print function. 4 00:00:16,860 --> 00:00:19,310 It's an example of for beauty in function 5 00:00:23,340 --> 00:00:28,560 but in this lecture we're going to talk about Kasa functions and custom functions are super useful. 6 00:00:28,700 --> 00:00:32,510 I'll referred to custom functions as just functions from now on. 7 00:00:32,810 --> 00:00:39,270 So a function is an algorithm but even by us that computes in alterable given a certain input. 8 00:00:39,710 --> 00:00:42,060 The key benefit of function is that. 9 00:00:42,080 --> 00:00:48,490 Or you can write a function only once but you can use it as many times as you want by just calling it. 10 00:00:48,620 --> 00:00:50,500 Which is very simple. 11 00:00:50,570 --> 00:00:53,410 Here is how to write a function in Python. 12 00:00:53,420 --> 00:01:01,770 I'm going to create a function here that calculates the coast of potatoes unit price and the amount. 13 00:01:02,240 --> 00:01:10,400 So we use the word keyword def to tell Python that we are about to define a function and after that 14 00:01:10,430 --> 00:01:12,650 we choose a name for our function. 15 00:01:12,670 --> 00:01:16,670 I will name my faction but take two cost. 16 00:01:16,910 --> 00:01:23,900 Once we are either a function name we said the input parameters for the function and we can now write 17 00:01:23,900 --> 00:01:27,970 what function will compute and what it turns out. 18 00:01:28,220 --> 00:01:36,410 In this case we want to compute the cost of potatoes given the price on them and so close equals potato 19 00:01:36,410 --> 00:01:45,310 price dimes and moaned and we also want let's say to print out the potato type. 20 00:01:45,660 --> 00:01:53,130 Now we are printing all the potato type but we also want to return the calculated closed where the function 21 00:01:53,130 --> 00:01:54,510 is executed later. 22 00:01:54,660 --> 00:02:00,160 We can either do it using the print function or we can use the return keyword. 23 00:02:00,520 --> 00:02:07,800 I'm using the return keyword here and see now how easy it is to call the function once we have created 24 00:02:07,800 --> 00:02:08,290 it. 25 00:02:09,000 --> 00:02:14,490 So potato goes and we write the values which are called attributes. 26 00:02:14,490 --> 00:02:22,230 Now notice that we are imputing values for each of the parameters in the given order and what we get 27 00:02:22,230 --> 00:02:26,220 is a printed potato type and the computed cost. 28 00:02:26,400 --> 00:02:31,050 You can now execute the function as many times as you want using different values. 29 00:02:31,050 --> 00:02:37,920 And the last thing to mention here is that we are old fashioned in the Python console as I have told 30 00:02:37,920 --> 00:02:38,490 you before. 31 00:02:38,490 --> 00:02:40,490 This is a platform for testing. 32 00:02:40,650 --> 00:02:47,080 If we close I on we will lose our function the Phoenician will not be able to call it anymore. 33 00:02:47,130 --> 00:02:52,290 So normally we want to store our function in a script for later use. 34 00:02:52,410 --> 00:02:56,810 In that case we have to write it in a dot by script. 35 00:02:56,820 --> 00:03:00,750 Once we do that we can't really use the function in the future. 36 00:03:00,870 --> 00:03:03,440 So that was how to define and call a function.