1 00:00:11,230 --> 00:00:17,920 Hello, everybody, I'm happy that you're here and I'm really proud in each and every one of you that 2 00:00:17,920 --> 00:00:26,500 got up until this point, I can surely say that most of the content of the course is behind us for one 3 00:00:26,500 --> 00:00:30,040 side, from one point of view is a happy thing. 4 00:00:30,340 --> 00:00:34,050 But we should not forget what's coming up next. 5 00:00:34,450 --> 00:00:40,510 So what's waiting for us now is the massive stopping method. 6 00:00:40,510 --> 00:00:49,180 A method is basically a block of code that has a certain headline, and then this block of code can 7 00:00:49,180 --> 00:00:50,170 be executed. 8 00:00:50,170 --> 00:00:56,680 Once we call it OK, it will not be executed by itself, even if it appears in the code we should call 9 00:00:56,680 --> 00:00:56,910 it. 10 00:00:58,210 --> 00:01:07,390 So this will be our next lecture's methods is a very important part in each and every programming language. 11 00:01:07,600 --> 00:01:16,780 And in Python in particular, which is based on OP, you might have heard this term OPIS object oriented 12 00:01:16,780 --> 00:01:22,900 programming, and every professional program in the world knows what these OLP. 13 00:01:22,900 --> 00:01:30,820 And also I'm sure that those of you who want actually to find jobs in programming, you will be surely, 14 00:01:31,060 --> 00:01:37,570 surely you're going to be asked regarding methods and OLP in your interviews. 15 00:01:39,010 --> 00:01:41,020 So that's about this thing. 16 00:01:42,000 --> 00:01:48,160 Additionally, I just want to say that from one hand, the following topics will be a bit challenging 17 00:01:48,160 --> 00:01:55,690 for one side, but from the other side, you should not worry at all, because the thing is that I'm 18 00:01:55,870 --> 00:02:04,710 also I'm always in focus regarding the level of difficulty of the topics. 19 00:02:04,710 --> 00:02:07,540 So these topics would be be challenging. 20 00:02:07,540 --> 00:02:16,030 But from the other hand, I'm going to give you more life coding examples and more perspectives once 21 00:02:16,030 --> 00:02:20,200 we're going over the slides, going to explain everything two or three times. 22 00:02:21,010 --> 00:02:22,630 So don't worry you. 23 00:02:22,630 --> 00:02:24,910 I got your back regarding this part. 24 00:02:26,470 --> 00:02:26,920 All right. 25 00:02:26,920 --> 00:02:30,880 So let's begin what easy method in Python. 26 00:02:30,890 --> 00:02:39,370 So, like I just said, a method is a block of code which only runs when it is called also the method. 27 00:02:39,580 --> 00:02:46,030 You can pass the variables or collections into it from the execution point. 28 00:02:46,870 --> 00:02:50,680 Is it just mentioned there is the method itself declaration. 29 00:02:50,950 --> 00:02:59,230 And then there's a second second thing, which is when you call the method, which is called method 30 00:02:59,240 --> 00:03:00,150 execution. 31 00:03:01,120 --> 00:03:08,860 So in the method execution part there you can pass variables or whatever into the method, then they're 32 00:03:08,860 --> 00:03:10,910 going to be used inside the method. 33 00:03:12,700 --> 00:03:13,810 Sounds a bit tough. 34 00:03:14,110 --> 00:03:15,240 Sounds a bit hard. 35 00:03:15,250 --> 00:03:15,970 Don't worry. 36 00:03:15,970 --> 00:03:18,610 You will see many examples in the following minutes. 37 00:03:20,400 --> 00:03:27,960 All right, an additional advantage of matinées, methods, first of all, methods connected with a 38 00:03:27,960 --> 00:03:37,530 strong connection to the following topic, which is classes and objects, they are connected very much. 39 00:03:38,130 --> 00:03:42,300 And basically what methods gives us it gives us a great power. 40 00:03:42,540 --> 00:03:50,310 It gives us to avoid duplication because you can create a certain code and then you can reuse it. 41 00:03:50,310 --> 00:03:56,640 Or in other words, you can execute it several times by your command whenever you need it. 42 00:03:56,880 --> 00:04:00,890 And you don't need to create the same variables and same loops or whatever. 43 00:04:01,050 --> 00:04:02,250 Again and again. 44 00:04:02,430 --> 00:04:05,010 You can simply just call it whenever you need it. 45 00:04:05,490 --> 00:04:06,090 All right. 46 00:04:07,440 --> 00:04:14,310 So let's go over quickly regarding how methods work and what can it do. 47 00:04:15,540 --> 00:04:18,930 So I'm going to go over the boards and also explain every one of them. 48 00:04:20,220 --> 00:04:23,370 A second name of method is a function. 49 00:04:23,640 --> 00:04:30,180 So whenever you're going to look something, some questions regarding methods in Google or Stack Overflow 50 00:04:30,180 --> 00:04:33,990 or whatever, if you encounter the term function. 51 00:04:34,260 --> 00:04:36,720 So function is method and method. 52 00:04:36,720 --> 00:04:38,310 Its function is the same thing. 53 00:04:38,410 --> 00:04:39,600 Just has two names. 54 00:04:39,990 --> 00:04:40,500 All right. 55 00:04:42,210 --> 00:04:44,180 After a method is created. 56 00:04:44,240 --> 00:04:54,000 OK, so you have Pathé, which is method creation, then you have Babi method call-out or method execution. 57 00:04:54,000 --> 00:04:56,070 So it's different parts in the code. 58 00:04:56,070 --> 00:04:58,980 You have separate lines of code for it. 59 00:04:59,340 --> 00:05:03,240 We'll see it right here in the example in just a minute. 60 00:05:04,050 --> 00:05:14,430 OK, so you first you first created, then you call it and the execution is done in the module level, 61 00:05:14,430 --> 00:05:23,010 meaning it does not happen in the indention under the method and it happens after the methods block 62 00:05:23,010 --> 00:05:24,980 itself outside of the method. 63 00:05:25,020 --> 00:05:29,340 OK, outside of the method, we execute it next. 64 00:05:29,340 --> 00:05:33,510 Both is once the method is executed, all the code inside it will run. 65 00:05:33,840 --> 00:05:41,460 We already know this basic guideline from you, statements and for loops that once, for example, if 66 00:05:41,460 --> 00:05:47,510 we created if statement so everything if the statement is correct. 67 00:05:47,730 --> 00:05:57,450 So all the code under the if statement declaration will run as a whole unit and how the pichon will 68 00:05:57,450 --> 00:06:02,220 know that this code is under the if basically very simple way. 69 00:06:02,760 --> 00:06:08,550 If you have intention for these lines under the if statement, you will know that this is that statement's 70 00:06:08,550 --> 00:06:10,280 content commands. 71 00:06:10,290 --> 00:06:10,650 All right. 72 00:06:11,910 --> 00:06:21,830 By content, I mean it's inside the if OK, because you can best data in the form of variables or collections 73 00:06:21,840 --> 00:06:24,630 into the method from the execution command. 74 00:06:24,990 --> 00:06:31,040 So again, we said we have the execution, we have the creation path and the execution part. 75 00:06:31,410 --> 00:06:37,590 So if you want to pass some variable from the execution part inside the method, you can do it. 76 00:06:37,890 --> 00:06:43,800 You will see shortly an example for this as well in this presentation later on. 77 00:06:44,790 --> 00:06:47,120 OK, and one last thing. 78 00:06:47,330 --> 00:06:56,460 How do we recognize that we are looking in a method once we see it, for example, in loops, though, 79 00:06:56,460 --> 00:07:02,940 the key word for by that we can recognize that we are dealing with a for loop. 80 00:07:03,450 --> 00:07:07,140 But in the methods case, there is this word here def. 81 00:07:07,590 --> 00:07:14,430 And once you see this different key word, you know that ahead of you there is a method from here. 82 00:07:14,430 --> 00:07:16,490 I think it's very convenient for us to see. 83 00:07:16,500 --> 00:07:21,100 First, simple example and let's look at it straight away. 84 00:07:21,660 --> 00:07:29,150 So the first line is method declaration, same as we did with each statement declaration or while loops 85 00:07:29,760 --> 00:07:30,600 declaration. 86 00:07:30,930 --> 00:07:33,840 So this is the the method declaration. 87 00:07:34,120 --> 00:07:40,470 The first key word is that right afterwards we give the name of the method, then we have round brackets 88 00:07:40,470 --> 00:07:43,040 and then we have the two dots special sine. 89 00:07:44,940 --> 00:07:47,460 OK, so this is the declaration. 90 00:07:47,700 --> 00:07:49,870 Then one line behind it. 91 00:07:49,900 --> 00:07:56,640 The second line is the methods, content and by chance would know that this is the method is going to 92 00:07:56,640 --> 00:08:03,420 be hard because you're going to have indention here at this line in every additional line which you 93 00:08:03,420 --> 00:08:07,450 would like to create under your method method. 94 00:08:07,890 --> 00:08:13,500 OK, so this is the method, the content part and right here below. 95 00:08:13,530 --> 00:08:17,390 OK, we went down for a few lines just for this text to fit in. 96 00:08:17,400 --> 00:08:23,820 There's no special reason that there is lots of spaces here just because all my explanations would fit 97 00:08:23,820 --> 00:08:24,180 here. 98 00:08:24,480 --> 00:08:32,820 But we can see here is the method of execution and you can see that there is no intention here regarding 99 00:08:32,820 --> 00:08:35,460 to the method of execution command. 100 00:08:35,730 --> 00:08:38,910 There's no intention like here in the brain, for example. 101 00:08:39,720 --> 00:08:43,740 And basically, only if this path exists, the method will run. 102 00:08:44,400 --> 00:08:47,340 So if you remove the last line and you right. 103 00:08:47,340 --> 00:08:51,680 Click in parts of the file and run it, nothing will happen. 104 00:08:52,010 --> 00:08:54,350 OK, nothing will happen. 105 00:08:55,200 --> 00:09:00,570 So we have to have this last line right here in order for this method to run. 106 00:09:00,780 --> 00:09:03,510 So basically here we call it out, please run. 107 00:09:04,500 --> 00:09:10,350 And then it goes from here from this line goes straight up to the method and goes inside, then runs 108 00:09:10,350 --> 00:09:11,760 whatever is inside the method. 109 00:09:12,930 --> 00:09:15,880 Very simple logic of how methods work. 110 00:09:16,050 --> 00:09:16,410 All right. 111 00:09:16,420 --> 00:09:18,540 Nothing's too complicated in this case. 112 00:09:19,530 --> 00:09:25,710 As you can see, this this this example, it has no best to it, OK? 113 00:09:25,710 --> 00:09:33,330 We don't see here in the brackets some variables that we want to insert into the method and also in 114 00:09:33,330 --> 00:09:36,000 the execution level, we don't see any variables. 115 00:09:36,360 --> 00:09:44,610 So let's see how could we create methods that will contain variables and how can we do it basically? 116 00:09:44,610 --> 00:09:44,950 All right. 117 00:09:45,570 --> 00:09:52,260 So in the previous example, we have seen a method that does not have any did not have any argument 118 00:09:52,260 --> 00:09:52,890 inside it. 119 00:09:52,890 --> 00:09:53,310 All right. 120 00:09:53,580 --> 00:09:59,250 Now, let's have a look on the on one that gets variables inserted into it. 121 00:10:00,880 --> 00:10:01,200 Right. 122 00:10:01,210 --> 00:10:08,490 So basically, right after the methods name, right after def, then methods name and inside the square 123 00:10:08,490 --> 00:10:15,900 brackets, we can put the the arguments or those of you who have difficulty to understand what our arguments, 124 00:10:16,000 --> 00:10:21,450 arguments are basically variables, any type of variables and collections. 125 00:10:22,020 --> 00:10:30,660 And we can put any variables we want inside the method in the execution level and then it will go inside 126 00:10:30,660 --> 00:10:31,200 the method. 127 00:10:31,470 --> 00:10:33,540 We will see here the sketch in a few seconds. 128 00:10:35,220 --> 00:10:35,770 All right. 129 00:10:35,790 --> 00:10:41,400 So in this example, we have the variable age, OK? 130 00:10:42,540 --> 00:10:44,070 And this is what we want to pass. 131 00:10:44,550 --> 00:10:47,430 OK, so let's see this example straight ahead. 132 00:10:48,850 --> 00:10:55,960 We have this one on this example right here, and we can see her death, my function, which is the 133 00:10:56,260 --> 00:11:02,320 which is the method, and inside here, inside the wrong brackets, we can see the variable, which 134 00:11:02,320 --> 00:11:02,930 is age. 135 00:11:03,580 --> 00:11:04,300 All right. 136 00:11:04,990 --> 00:11:07,500 And below it, we can also see print. 137 00:11:07,540 --> 00:11:11,290 The age is casting and also the age goes here. 138 00:11:11,590 --> 00:11:13,630 What the age is not like. 139 00:11:13,630 --> 00:11:15,250 We need to tell this method. 140 00:11:15,670 --> 00:11:16,740 What do we mean? 141 00:11:16,750 --> 00:11:18,010 Age equals two. 142 00:11:18,250 --> 00:11:19,420 OK, we need to tell it. 143 00:11:19,420 --> 00:11:20,740 Age equals to what? 144 00:11:22,990 --> 00:11:25,870 And this can be done in the execution level. 145 00:11:26,110 --> 00:11:32,380 All right, so right here, these three, my function, my function and my function is the execution 146 00:11:32,380 --> 00:11:32,820 level. 147 00:11:33,280 --> 00:11:40,120 And here we can see the concept that I mentioned in the beginning of the lecture that methods can be 148 00:11:40,720 --> 00:11:45,880 are used to get the code to be reusable. 149 00:11:46,240 --> 00:11:50,560 OK, so this method is reusable and it's dynamic. 150 00:11:50,740 --> 00:11:56,800 By dynamic, I mean that you can put any variable you want here and each time you execute, you can 151 00:11:56,800 --> 00:11:58,120 put a different one. 152 00:11:58,150 --> 00:12:00,020 OK, so it's like magic, right? 153 00:12:00,370 --> 00:12:06,160 I really I really excited regarding this topic once I studied it for the first time because you have 154 00:12:06,160 --> 00:12:13,570 the same code and each time you got different variables going inside here, just whatever you want, 155 00:12:13,570 --> 00:12:14,510 you can put inside. 156 00:12:15,700 --> 00:12:20,430 So we go in these two for these two first line we already understand. 157 00:12:20,440 --> 00:12:22,890 Let's talk about the execution level right here. 158 00:12:23,140 --> 00:12:25,710 Also mentioned that you don't have indention here. 159 00:12:25,720 --> 00:12:26,080 All right. 160 00:12:27,910 --> 00:12:28,330 All right. 161 00:12:28,330 --> 00:12:29,500 So here. 162 00:12:29,560 --> 00:12:30,890 Same as before. 163 00:12:30,940 --> 00:12:33,490 Same as the previous example right here. 164 00:12:33,820 --> 00:12:36,840 We are calling we're executing the method. 165 00:12:36,850 --> 00:12:41,410 OK, so these three lines are execution of the method. 166 00:12:42,220 --> 00:12:46,660 But we can see up in here that the method needs to get a variable. 167 00:12:46,870 --> 00:12:53,350 And if we don't give it a variable, if we leave the thing here empty, so we're going to get an error 168 00:12:53,350 --> 00:12:59,070 because the method expects to receive something from the execution level right here. 169 00:12:59,410 --> 00:13:01,510 And if you don't pass anything, you will have an error. 170 00:13:02,020 --> 00:13:09,040 OK, so in the first case, I just pass here the number 25 and you can see that this line executes the 171 00:13:09,040 --> 00:13:09,820 method above. 172 00:13:10,720 --> 00:13:20,200 So once I run the the whole file of this code is in the number twenty five goes from the execution level 173 00:13:20,560 --> 00:13:23,890 into the method declaration. 174 00:13:23,900 --> 00:13:31,060 I'll be here and number two and from number two, it goes straight ahead here to the print and the print 175 00:13:31,060 --> 00:13:34,060 gets the variable from the brackets right here. 176 00:13:34,330 --> 00:13:37,210 So this is the flow one, two and three. 177 00:13:38,440 --> 00:13:39,580 Not too tough. 178 00:13:39,580 --> 00:13:47,990 I think even after hearing all the explanations regarding how things work, you can put a variable here. 179 00:13:47,990 --> 00:13:56,650 We can also do not put it variable here, but you need to have consistency, consistency between the 180 00:13:56,650 --> 00:14:05,110 execution level and the method declaration, because if you put here twenty five, for example, but 181 00:14:05,110 --> 00:14:10,750 inside these round brackets is going to stay empty, you're also going to have an error because these 182 00:14:10,750 --> 00:14:15,220 two should be sinked an additional example. 183 00:14:15,580 --> 00:14:23,320 For example, you want to best two variables we have seen in the Bullis that need there needed to be 184 00:14:23,500 --> 00:14:25,020 divided by Colma. 185 00:14:25,240 --> 00:14:25,840 All right. 186 00:14:26,180 --> 00:14:26,780 Not sure. 187 00:14:26,980 --> 00:14:27,490 See it. 188 00:14:32,870 --> 00:14:37,460 OK, right here, you just need to separate them by Colma. 189 00:14:37,850 --> 00:14:48,170 All right, so if he were to variables for example 25 then Colma then we're also going to have an error 190 00:14:48,350 --> 00:14:56,090 because right here at the top of the declaration we have only one variable mentioned here and when we 191 00:14:56,180 --> 00:14:59,280 passing two variables, you will get confused and give us an error. 192 00:14:59,830 --> 00:15:07,300 OK, so we have to, we must have consistency between the execution and the declaration placements. 193 00:15:07,400 --> 00:15:13,180 OK, again, as I already said, each stop, each subtopic here. 194 00:15:13,190 --> 00:15:16,000 I'm going to explain in several point of views. 195 00:15:16,220 --> 00:15:21,410 So those of you who are struggling to understand, let's listen to this part right here. 196 00:15:22,610 --> 00:15:24,560 So the flow, what happens up in here? 197 00:15:24,590 --> 00:15:31,040 Basically, we pass a variable to the method from the execution placement right here, number one. 198 00:15:31,040 --> 00:15:32,690 Twenty five here. 199 00:15:32,690 --> 00:15:37,310 We add the number with our keyboards and we choose whatever we want. 200 00:15:38,470 --> 00:15:46,180 All right, that variable will pass and we shall use it inside the method. 201 00:15:46,540 --> 00:15:51,000 OK, so this variable will be used inside the method in number three here. 202 00:15:51,580 --> 00:15:55,430 Then the value is accepted in the method of the operation. 203 00:15:55,690 --> 00:15:57,170 So we send it from here. 204 00:15:57,190 --> 00:15:58,490 It's received here. 205 00:15:58,490 --> 00:16:01,090 And the method declaration inside. 206 00:16:01,090 --> 00:16:03,450 Number two, here it is received. 207 00:16:03,460 --> 00:16:08,110 And from there the variable is used to being called. 208 00:16:08,320 --> 00:16:13,560 The variable is used to where it is being called inside the method. 209 00:16:13,810 --> 00:16:19,900 In our case, we have the print actually print action here, the print command. 210 00:16:20,140 --> 00:16:22,920 And here we're using the each variable. 211 00:16:24,610 --> 00:16:25,780 I think that's about it. 212 00:16:25,780 --> 00:16:31,600 I think it's enough for the introduction and it's enough for it's not really an introduction. 213 00:16:31,600 --> 00:16:32,620 It's more than that. 214 00:16:33,250 --> 00:16:39,940 It's enough for the very easy to understand how they work, how do we recognize them, what are the 215 00:16:39,940 --> 00:16:47,470 characteristics and what are the benefits of methods, methods without variable and method with variable. 216 00:16:47,860 --> 00:16:50,050 So we cover this whole thing up. 217 00:16:50,770 --> 00:16:58,120 And I guess that you will see some live code examples in the next video to understand it better. 218 00:16:58,600 --> 00:17:01,240 OK, so we're done with this one. 219 00:17:01,240 --> 00:17:03,460 I'll show you the next video and thank you.