1 00:00:12,000 --> 00:00:15,960 Hello, everybody, and welcome to the Methods Advanced Lecture. 2 00:00:16,330 --> 00:00:22,050 Before we begin, let's have a quick overview regarding the topics that we have covered in previous 3 00:00:22,050 --> 00:00:22,660 lectures. 4 00:00:23,250 --> 00:00:32,070 OK, we started off methods, basics, where we were, where we encountered basics, theory, terminology 5 00:00:32,310 --> 00:00:39,630 of what our methods and what they are capable of right after we have seen several examples. 6 00:00:39,660 --> 00:00:47,810 The first example was a simple method declaration and also method execution right here straightaway. 7 00:00:47,820 --> 00:00:52,950 Afterwards, we have seen that we can pass arguments inside and method. 8 00:00:53,640 --> 00:00:58,020 Basically, we have set a number of variable right here. 9 00:00:58,020 --> 00:01:06,810 And also we have seen that data flow that that goes from the execution and goes to the declaration and 10 00:01:06,810 --> 00:01:09,860 inside the methods content right here. 11 00:01:10,680 --> 00:01:12,300 OK, then we passed all. 12 00:01:12,300 --> 00:01:16,440 We passed on to the mid-level lecturer's of methods. 13 00:01:16,440 --> 00:01:18,930 And here we have seen some more cool tricks. 14 00:01:19,740 --> 00:01:22,920 We have seen that we can use default values inside methods. 15 00:01:22,920 --> 00:01:30,240 And in cases that we are not having input inside it, we will not have an error or we will avoid an 16 00:01:30,240 --> 00:01:34,710 error or an exception by putting a default value right here. 17 00:01:36,420 --> 00:01:44,520 And then we have studied also the methods can receive variables from the other hand, also can return 18 00:01:44,850 --> 00:01:51,210 variables, and this return value can be used outside of the method in our purposes. 19 00:01:51,210 --> 00:01:56,040 Whatever we want, we can even pass it on to a different method as well. 20 00:01:57,030 --> 00:01:58,980 And we have covered this one as well. 21 00:01:59,660 --> 00:02:04,830 OK, so I think that now we're ready to go for work forward to methods advanced. 22 00:02:05,100 --> 00:02:07,830 And before we begin, just want to have a few words. 23 00:02:08,670 --> 00:02:18,960 OK, so as in the advanced lecture would be a bit more challenging and especially the methods just preparing 24 00:02:18,960 --> 00:02:25,500 you that you will see some examples and some theory here that is a bit more challenging. 25 00:02:26,400 --> 00:02:30,780 But worry not because I have backup for you as well. 26 00:02:30,930 --> 00:02:38,190 I'm going to show you live examples regarding each of these examples, which is going to executed on 27 00:02:38,210 --> 00:02:38,960 PI charm. 28 00:02:39,240 --> 00:02:41,130 So everything's going to be just fine. 29 00:02:41,970 --> 00:02:45,150 And also, just a quick tip for life. 30 00:02:45,840 --> 00:02:50,940 Each time I have a big problem, I always break it down into small pieces. 31 00:02:51,450 --> 00:02:56,820 Let's say, for example, like a young man is thinking, how am I going to bring my life together? 32 00:02:57,030 --> 00:02:58,260 I need to have a wife. 33 00:02:58,260 --> 00:02:59,290 I need to have a car. 34 00:02:59,300 --> 00:03:01,200 Do they have a job, a house? 35 00:03:01,500 --> 00:03:04,470 And all these seems really threatening at the beginning. 36 00:03:04,890 --> 00:03:11,760 But then once he starts to breaking it down to small pieces, for example, I need to study I need to 37 00:03:11,760 --> 00:03:18,120 study a certain field and then find a job according to this field, and then to go and meet some people 38 00:03:18,120 --> 00:03:20,180 and then meet a girl and so on and so on. 39 00:03:20,520 --> 00:03:26,880 So once you have a plan, nothing is threatening and everything is just turns to be easy. 40 00:03:26,880 --> 00:03:27,150 Right. 41 00:03:28,140 --> 00:03:35,760 So this is exactly the type of studying that I believe in, and I think that will be just fine. 42 00:03:36,300 --> 00:03:36,660 All right. 43 00:03:36,660 --> 00:03:37,740 So let's begin. 44 00:03:37,860 --> 00:03:38,190 All right. 45 00:03:38,190 --> 00:03:42,630 So first of all, we have seen in previous lectures, let me just fix the sentence. 46 00:03:43,470 --> 00:03:50,700 In previous lectures, we have seen simple examples. 47 00:03:52,510 --> 00:03:57,650 Of methods and some foundational features of it. 48 00:03:58,630 --> 00:04:08,980 OK, and we can also encounter a keyword arguments, which we just talked about briefly in the in the 49 00:04:08,980 --> 00:04:10,640 first lecture right here. 50 00:04:10,960 --> 00:04:14,530 OK, so we have seen that we can pass arguments. 51 00:04:14,560 --> 00:04:21,260 Arguments are basically variables or collections of data, basically called arguments. 52 00:04:21,280 --> 00:04:28,960 OK, so we know that the arguments are variables and collections, but what are basically keyword arguments? 53 00:04:29,470 --> 00:04:32,270 We already know what it is like. 54 00:04:32,270 --> 00:04:35,280 It's the term which is not familiar to us. 55 00:04:35,290 --> 00:04:36,250 Let's see what it is. 56 00:04:36,940 --> 00:04:45,970 OK, so basically we can pass keyword arguments and the keyword arguments are like variables, but this 57 00:04:45,970 --> 00:04:52,440 time the variables are not coming in the form of a single string or a single number. 58 00:04:52,690 --> 00:04:55,360 The common syntax of a key value. 59 00:04:55,540 --> 00:05:02,670 OK, and where we do, we are familiar with the key value syntax, obviously, from Dictionary Stoppie, 60 00:05:02,950 --> 00:05:03,530 correct? 61 00:05:03,810 --> 00:05:04,210 Yeah. 62 00:05:04,810 --> 00:05:13,030 OK, so let's see a quick example here of what's going on and how should we handle these keyword arguments. 63 00:05:13,180 --> 00:05:13,600 All right. 64 00:05:14,290 --> 00:05:19,680 So here we have a declaration of a method which we already know how it looks. 65 00:05:19,690 --> 00:05:22,140 OK, form Brandes is our method. 66 00:05:22,420 --> 00:05:30,250 We've said here three variables and pay attention to these variables are mixed in order and there not 67 00:05:30,250 --> 00:05:31,040 by order. 68 00:05:31,180 --> 00:05:39,910 OK, and right here below, we have the execution line where we have a different type of variables passed 69 00:05:39,910 --> 00:05:40,780 into the method. 70 00:05:41,140 --> 00:05:50,140 And you can see that they are like two items inside each cell, which is a key and a value basically 71 00:05:50,140 --> 00:05:52,870 looks very, very like a dictionary. 72 00:05:54,190 --> 00:05:58,660 So brand one key fits for the apple value. 73 00:05:58,660 --> 00:06:02,210 Brand two is Siami and Brantley's L.G.. 74 00:06:02,500 --> 00:06:08,950 OK, and then inside we pass all of these variables inside the method and then inside the method. 75 00:06:08,950 --> 00:06:14,650 What we're seeing here is that we're trying to print brand three variable. 76 00:06:14,650 --> 00:06:15,150 Correct. 77 00:06:16,600 --> 00:06:25,600 And once once Python recognizes that we're passing keyword arguments inside it, inside the method, 78 00:06:25,900 --> 00:06:34,780 he knows that once we call out one of these variables, it should print as it should use the value of 79 00:06:34,810 --> 00:06:35,560 the key. 80 00:06:35,630 --> 00:06:44,460 OK, so in our case, once we are passing by three equals L.G. right here and then we call it out. 81 00:06:44,650 --> 00:06:46,750 So the output will show us. 82 00:06:46,960 --> 00:06:48,950 The third brand is L.G.. 83 00:06:49,000 --> 00:06:52,780 OK, so it will print out the value of brand three. 84 00:06:53,080 --> 00:06:55,450 OK, so these are this is the logic's. 85 00:06:55,840 --> 00:07:01,690 And I think that we will have much more confidence and we'll just see it inside by chance as well. 86 00:07:01,960 --> 00:07:10,020 And let's try to like sorry, let's try to actually execute this code and see it with our own eyes. 87 00:07:11,900 --> 00:07:22,400 All right, so I've created here some initial some glass for these examples, and once we execute it, 88 00:07:22,400 --> 00:07:25,000 OK, this is the copy paste of the code. 89 00:07:25,340 --> 00:07:34,100 So once we execute it so you can see here, the third brand is LG while here, just copied this line 90 00:07:34,100 --> 00:07:34,520 as well. 91 00:07:35,180 --> 00:07:42,270 We see that it just execute the code and shows us the value of this key here. 92 00:07:42,290 --> 00:07:45,610 This is this is what it shows us the value of brand three. 93 00:07:45,950 --> 00:07:46,430 All right. 94 00:07:46,970 --> 00:07:48,110 Not very hard. 95 00:07:48,140 --> 00:07:51,200 OK, so just one rule here. 96 00:07:51,590 --> 00:07:57,890 Once you pass keyword arguments and then you use it inside the method, the argument. 97 00:07:57,900 --> 00:08:01,000 So the argument will show the value of the key. 98 00:08:01,280 --> 00:08:01,910 That's it. 99 00:08:01,910 --> 00:08:02,750 Plain, simple. 100 00:08:04,590 --> 00:08:13,740 All right, so from here, let's go to the second topic, which are arbitrary arguments and basically 101 00:08:13,740 --> 00:08:21,580 what arbitrary word means is not something which always will be the same occurrence, like random. 102 00:08:22,080 --> 00:08:29,790 So we're not sure we're going to see a method now that we're not sure about. 103 00:08:29,790 --> 00:08:34,320 How many variables should it get on each time it will be executed? 104 00:08:34,350 --> 00:08:41,740 OK, so basically in these examples, we have seen that from the previous election. 105 00:08:41,810 --> 00:08:42,030 Right. 106 00:08:42,090 --> 00:08:42,380 Yeah. 107 00:08:42,630 --> 00:08:46,350 So we have seen here that only one variable can be passed inside. 108 00:08:47,130 --> 00:08:54,930 And for example, if I put two variables here, so we'll have an error because the method is not expecting 109 00:08:54,930 --> 00:08:55,750 to variables. 110 00:08:56,070 --> 00:09:04,080 So now we're going to learn how to overcome this by having arbitrary arguments passed into the method. 111 00:09:04,160 --> 00:09:11,190 OK, so Python gives us an option to have an arbitrary number of arguments when we are dealing with 112 00:09:11,190 --> 00:09:18,060 methods, meaning if you do not know how many arguments, which are variables or collections will be 113 00:09:18,060 --> 00:09:23,460 passed into a method and arbitrary arguments approach is the right one for us. 114 00:09:25,080 --> 00:09:29,490 OK, so let's see the implementation and how do we actually use it? 115 00:09:29,560 --> 00:09:31,860 OK, so you have an example right here. 116 00:09:33,030 --> 00:09:38,730 We have a declaration of of a method of a method here and inside the declaration. 117 00:09:38,940 --> 00:09:46,590 You can see here a special starky, OK, which is basically can be done by shift in the number eight 118 00:09:46,830 --> 00:09:48,560 inside your keyboard. 119 00:09:48,780 --> 00:09:58,770 And once we are adding this special key, the star here, the the method will address this variable 120 00:09:58,770 --> 00:10:01,170 differently from simple variables. 121 00:10:01,410 --> 00:10:03,370 And let's see how exactly. 122 00:10:03,400 --> 00:10:10,800 OK, let's go always to the execution and level to see what we are passing into the method, because 123 00:10:10,830 --> 00:10:14,000 this is the entry gate of the method. 124 00:10:14,280 --> 00:10:20,520 So you can see that we have executed the comp, the clothing company's method two times now. 125 00:10:20,790 --> 00:10:25,650 And in the first time we have passed three variables into it. 126 00:10:25,800 --> 00:10:28,890 But in the second time we passed on two variables. 127 00:10:29,340 --> 00:10:36,570 And you obviously can trust me that this case did not come up with any errors, OK, because this was 128 00:10:36,570 --> 00:10:37,310 intentional. 129 00:10:37,650 --> 00:10:46,950 Once we have tried it with the methods that we studied in the basics lecture, if we will pass you two 130 00:10:46,950 --> 00:10:50,700 variables, it would show us an error or an exception. 131 00:10:50,700 --> 00:10:52,140 And it's a different name for error. 132 00:10:52,590 --> 00:10:56,550 And we cannot continue with our call because it will fail. 133 00:10:56,940 --> 00:11:04,350 OK, but now we're studying that if we're putting a small star icon, small star, our key and then 134 00:11:04,350 --> 00:11:06,520 putting a variable here. 135 00:11:06,660 --> 00:11:08,520 So this would not fail. 136 00:11:08,520 --> 00:11:13,020 You can execute one time with two variables and in a second time with three variables. 137 00:11:13,230 --> 00:11:17,370 OK, and let's go one line inside. 138 00:11:17,370 --> 00:11:19,830 OK, let's go into the content of the method. 139 00:11:20,040 --> 00:11:23,970 And you can see here that I've printed out the the following thing. 140 00:11:23,970 --> 00:11:31,130 The last company is OK plus and then clothing companies and you have square brackets and minus one, 141 00:11:32,310 --> 00:11:38,270 so the minus one inside the square brackets automatically should trigger your brains. 142 00:11:38,280 --> 00:11:46,140 The thing that we have a collection here, OK, because this type of syntax, as we can remember, we 143 00:11:46,140 --> 00:11:53,880 can recall it that this is how we pull out in cell values, out of collections. 144 00:11:53,880 --> 00:11:54,270 Correct. 145 00:11:54,270 --> 00:11:55,020 We studied it. 146 00:11:55,020 --> 00:11:56,190 We covered it a lot. 147 00:11:57,780 --> 00:12:01,000 So this is how we pull our values out of cells. 148 00:12:01,100 --> 00:12:04,110 OK, so this basically means one thing then. 149 00:12:04,110 --> 00:12:11,490 The variable that we have declared up in here is a sort of collection, and this is true. 150 00:12:11,520 --> 00:12:19,590 OK, so once you put here a single star, a key python knows that whatever comes from the execution 151 00:12:19,590 --> 00:12:27,430 line goes here, Open-top here, OK, whatever goes here, this will be turned into a tuple collection. 152 00:12:27,490 --> 00:12:28,620 OK, this is a trick. 153 00:12:28,950 --> 00:12:30,600 You can put two variables. 154 00:12:30,600 --> 00:12:32,010 Three hundred. 155 00:12:32,490 --> 00:12:33,420 It doesn't matter. 156 00:12:34,170 --> 00:12:41,760 Every variable that you put here will be inserted into this clothing companies right here, which will 157 00:12:41,760 --> 00:12:43,680 be a tuple collection. 158 00:12:43,710 --> 00:12:51,360 OK, that way tuple can contain as many elements of the as you want and it does not have any limitation 159 00:12:51,570 --> 00:12:52,490 unless you give it. 160 00:12:52,800 --> 00:12:53,220 All right. 161 00:12:53,520 --> 00:13:02,070 So that that is the reason that inside the Mathas contents right here, if I want to pull out the last 162 00:13:02,070 --> 00:13:02,670 value. 163 00:13:03,370 --> 00:13:08,110 So I'm just using the minus one, and in the first execution, I'm going to have a chat and print it 164 00:13:08,110 --> 00:13:10,360 out and then the second one, the Adidas, OK? 165 00:13:12,810 --> 00:13:20,610 Also, as the previous lecture, did you have some confidence, let me just copy it and put it right 166 00:13:20,610 --> 00:13:23,860 here and let's execute and see what happens. 167 00:13:23,880 --> 00:13:24,270 All right. 168 00:13:26,100 --> 00:13:26,820 There you go. 169 00:13:27,090 --> 00:13:34,080 OK, so first execution, we've inserted one, two, three variables, it went inside the clothing. 170 00:13:34,080 --> 00:13:40,710 Clothing is a tuple, as we just mentioned, and then I asked it to give me the last value off the top. 171 00:13:40,860 --> 00:13:49,260 OK, so in the first case, the last value is and in the second case it is Adidas and it was ran successfully. 172 00:13:49,290 --> 00:13:57,630 OK, but in this case, if I did leave the store, we immediately have unexpected arguments here. 173 00:13:57,630 --> 00:14:03,720 And also if we run, it will fail because, OK, we have only one position. 174 00:14:03,960 --> 00:14:10,320 We have only one argument defined here in the declaration, but we're passing three variables and the 175 00:14:10,320 --> 00:14:10,890 first case. 176 00:14:10,890 --> 00:14:13,320 So we have a we have an execution error. 177 00:14:13,800 --> 00:14:20,990 So this is why this way we're putting a star here and this clothing company becomes a Toppo. 178 00:14:21,570 --> 00:14:26,730 OK, that's about this one. 179 00:14:26,970 --> 00:14:33,780 And let's go straight ahead to the last example, which I believe will be much easier after we have 180 00:14:33,780 --> 00:14:37,860 understood what happened here with arbitrary arguments. 181 00:14:39,890 --> 00:14:48,530 All right, so, Matt, we have seen and this example is that we're passing we were passing variables 182 00:14:48,530 --> 00:14:54,740 we can't pass one, two, three, 10 or 15 arguments inside this method right here. 183 00:14:54,980 --> 00:14:59,790 But now we're going to have an arbitrary keyword arguments. 184 00:14:59,810 --> 00:15:03,680 OK, so keyword arguments we already know, OK? 185 00:15:03,980 --> 00:15:10,820 These are key values, index variables, as we have seen in the first topic of this lecture. 186 00:15:11,150 --> 00:15:16,100 But now the word arbitrary is added to this term right here. 187 00:15:16,430 --> 00:15:25,310 So again, what this means is that we can execute a certain we can execute a certain method without 188 00:15:25,310 --> 00:15:29,810 knowing of how many variables or how many cells it will contain. 189 00:15:30,080 --> 00:15:42,080 OK, so we have used a single star icon inside the previous example of arbitrary arguments, but inside 190 00:15:42,080 --> 00:15:48,020 arbitrary keyword arguments, we're going to use the same technique, but this time we're going to add 191 00:15:48,020 --> 00:15:49,080 two stars in it. 192 00:15:49,940 --> 00:16:00,050 OK, let's see the example so you can see until that keyword arguments best into the method by using 193 00:16:00,050 --> 00:16:02,240 a key value structure. 194 00:16:02,540 --> 00:16:03,130 All right. 195 00:16:04,460 --> 00:16:05,050 Wow. 196 00:16:05,060 --> 00:16:13,130 Just a quick reminder up in here, it became a top all, but we have passed a simple variables without 197 00:16:13,130 --> 00:16:14,390 key value structure. 198 00:16:14,420 --> 00:16:15,770 OK, this is the difference. 199 00:16:17,480 --> 00:16:25,340 OK, so here passing key value arguments that we can pass in this execution, two variables, we can 200 00:16:25,340 --> 00:16:28,640 use an additional execution and best three variables. 201 00:16:28,940 --> 00:16:38,330 And once they get to the declaration level, a python recognizes it will pass key value. 202 00:16:38,960 --> 00:16:40,720 Have here we have two stars. 203 00:16:40,880 --> 00:16:47,220 So he immediately turns this variable right here into a dictionary. 204 00:16:47,240 --> 00:16:49,700 OK, it turns it into a dictionary. 205 00:16:51,500 --> 00:16:57,620 Let's copy it and as well see it and live execution example. 206 00:16:58,880 --> 00:17:00,060 Let's put it right here. 207 00:17:00,470 --> 00:17:01,100 All right. 208 00:17:01,230 --> 00:17:05,470 Let's change the quotation mark, and we should be fine. 209 00:17:05,930 --> 00:17:06,440 All right. 210 00:17:08,810 --> 00:17:11,060 We have some additional or no. 211 00:17:12,500 --> 00:17:14,440 Mike, for us, the indention, right? 212 00:17:16,000 --> 00:17:16,690 Like that. 213 00:17:16,720 --> 00:17:18,830 All right, so that's executed. 214 00:17:19,630 --> 00:17:25,290 OK, so what happened here is that I'm calling because this is a dictionary. 215 00:17:25,570 --> 00:17:30,910 So right here I'm extracting the value of this key, OK? 216 00:17:30,940 --> 00:17:31,960 The Keys model. 217 00:17:32,170 --> 00:17:40,360 And once I mention that the dictionary and inside square brackets state the key, so it should show 218 00:17:40,360 --> 00:17:45,310 me the value you can recall and also cover the material. 219 00:17:45,310 --> 00:17:51,250 If it's not familiar to you, you can cover the dictionaries lectures once again. 220 00:17:51,460 --> 00:17:54,630 But it's the same as we study regarding these dictionaries. 221 00:17:54,700 --> 00:18:00,460 This is how we extract values from a dictionary and that's about it. 222 00:18:00,850 --> 00:18:09,640 OK, so some more of this thing and we're passing here key values, arguments inside the method. 223 00:18:09,880 --> 00:18:17,410 And this time it's arbitrary, meaning I can execute at one time with two cells and in the second time 224 00:18:18,820 --> 00:18:20,770 I can put here, for example. 225 00:18:21,190 --> 00:18:22,660 You're right. 226 00:18:22,960 --> 00:18:24,190 And then put. 227 00:18:25,710 --> 00:18:32,160 Few thousand twenty or two thousand fifteen doesn't matter, and then executed. 228 00:18:33,160 --> 00:18:40,750 And we should not have any errors in the execution, but on the other hand, if we remove these two 229 00:18:40,750 --> 00:18:46,980 stars, you can see here that unexpected oral argument is fast and this is not good for us. 230 00:18:46,990 --> 00:18:50,440 And also, it should not be executed, will be incomplete. 231 00:18:51,020 --> 00:18:51,380 OK. 232 00:18:53,060 --> 00:18:58,590 So I think this covers our three most advanced topics regarding methods. 233 00:18:58,880 --> 00:19:06,380 I also recommend before going to the next lecture off practice to read this material by ourselves again 234 00:19:06,380 --> 00:19:13,790 and try to copy these examples into my charm and to play with it just to change your variables and to 235 00:19:13,790 --> 00:19:19,640 make some manipulations by yourselves, because experimenting is the best starting technique. 236 00:19:20,060 --> 00:19:26,430 OK, so go over the material again and then go to the next lecture where we will start practicing. 237 00:19:26,870 --> 00:19:27,980 Thank you and bye bye.