1 00:00:07,200 --> 00:00:12,850 Hi, everyone, in this section, we're going to talk a little bit more about how to structure your 2 00:00:12,850 --> 00:00:19,480 Python code and actually put in operation way easier because, you know, when your lines of code increase, 3 00:00:19,690 --> 00:00:22,660 you actually need to have some structure behind your code. 4 00:00:22,660 --> 00:00:27,580 And you cannot simply just write a line after line without thinking for that reason. 5 00:00:27,610 --> 00:00:33,280 Today, we're going to concentrate on different functions, classes and structures that will help to 6 00:00:33,280 --> 00:00:35,380 structure your code and use it way easier. 7 00:00:35,680 --> 00:00:39,910 This will add more structure to your code and make it more professional. 8 00:00:39,940 --> 00:00:45,190 So let's start by digging into what are actually the functions and how you can create function in Python 9 00:00:45,190 --> 00:00:47,800 in order to help your code be more useful. 10 00:00:48,850 --> 00:00:54,920 So here I am in my IT and I will create the new Python project in which we're going to add our data. 11 00:00:55,240 --> 00:00:59,890 So let's create next python functions and then finish. 12 00:01:00,130 --> 00:01:05,720 So here you have your project and I will create and say this project project by Dev Module. 13 00:01:06,160 --> 00:01:11,110 So let's call the package Python one two. 14 00:01:11,710 --> 00:01:12,060 True. 15 00:01:12,910 --> 00:01:16,300 Let's create a function in the name of the module. 16 00:01:16,300 --> 00:01:19,710 Will the quote unquote. 17 00:01:21,820 --> 00:01:27,220 OK, so you can see that now we're here for our module created and let's start creating functions. 18 00:01:27,970 --> 00:01:30,620 So first of all, how will you find functions in Python? 19 00:01:30,910 --> 00:01:37,770 So in Python you define a function also by just three letters, D.F. space. 20 00:01:37,780 --> 00:01:44,620 And this is how you define the function that in our case, our quick function, that we will assign 21 00:01:44,620 --> 00:01:47,330 a task to the user and you see what they mean. 22 00:01:47,650 --> 00:01:53,150 So when writing a function after the def keyword, you need to write the name or the function. 23 00:01:53,410 --> 00:02:02,650 So the name of dysfunction will be holer underscore usque and then you write to Brackett's, that's 24 00:02:02,650 --> 00:02:02,860 it. 25 00:02:03,490 --> 00:02:06,480 And automatically it gets to lots of Start-Up, so that's fine. 26 00:02:06,820 --> 00:02:13,600 So after you create the name of the function, you should go to the inner innovational in order to write 27 00:02:13,930 --> 00:02:16,180 what is going to be the speech and say just function. 28 00:02:16,450 --> 00:02:22,330 So usually between just break ins you can pass parameters or you can choose not to pass any parameters 29 00:02:22,330 --> 00:02:22,960 to the function. 30 00:02:23,200 --> 00:02:25,870 But later on, I'm going to talk more about this as well. 31 00:02:26,320 --> 00:02:30,840 So let's our functional print task. 32 00:02:31,510 --> 00:02:43,320 So your homework does not hold up and then print and then the task. 33 00:02:43,420 --> 00:02:51,680 So the task will be declared eight variable in item. 34 00:02:52,630 --> 00:02:56,120 OK, so this is the function and now you can call the function. 35 00:02:56,410 --> 00:03:02,830 So in order to know when the function success is needed, I want this to sentence's print. 36 00:03:03,940 --> 00:03:10,260 Start and then print and OK. 37 00:03:10,470 --> 00:03:15,580 So between these two statements, I will call the function and how we do this by simply defining the 38 00:03:15,580 --> 00:03:16,450 name of the function. 39 00:03:16,630 --> 00:03:19,040 So homework task in the brackets. 40 00:03:19,120 --> 00:03:22,690 OK, this is how we are calling the function from the call. 41 00:03:22,960 --> 00:03:30,130 Now I will run the project and you can see here that we are getting all the messages, your homework 42 00:03:30,130 --> 00:03:33,820 task declare a variable in Python. 43 00:03:34,030 --> 00:03:42,280 So this was the most simple case of function because here you do not need to pass any parameters. 44 00:03:42,460 --> 00:03:47,950 You simply called the function name and basically what was written inside the function to start working 45 00:03:48,130 --> 00:03:49,750 towards the two print statements. 46 00:03:50,230 --> 00:03:53,410 Now, the function also can give parameters. 47 00:03:53,680 --> 00:04:03,880 For example, if I write here language, OK, this means that in order to make this function work, 48 00:04:04,090 --> 00:04:09,850 we need to pass a variable that is going to be assigned to language in our function, or we're going 49 00:04:09,850 --> 00:04:13,850 to use the language in order to refer to the variable in how this is done. 50 00:04:14,560 --> 00:04:25,630 So I will remove them from here and I will simply write to declare a variable loss language. 51 00:04:26,110 --> 00:04:26,660 OK. 52 00:04:26,980 --> 00:04:33,010 And then when you're calling the function here in the brackets, you're going to pass the variable that 53 00:04:33,010 --> 00:04:35,350 you would like to be displayed inside of code. 54 00:04:36,190 --> 00:04:41,440 So this means every time a call the function, you can change the result of dysfunction depending on 55 00:04:41,440 --> 00:04:44,270 the input parameters that you up inside it. 56 00:04:44,680 --> 00:04:47,140 So I will write here, 57 00:04:50,110 --> 00:04:51,370 even though we're doing five. 58 00:04:51,430 --> 00:04:58,640 Of course, our challenge here is you will see that when I run the top, you're getting your Java. 59 00:04:59,050 --> 00:05:07,720 Now, if I call the function again, but this time I write C++, then you'll see that we're going to 60 00:05:07,720 --> 00:05:08,740 have two results. 61 00:05:10,240 --> 00:05:12,790 And in the first one, we're going to Taba. 62 00:05:12,790 --> 00:05:15,700 In the second one, we're using C++. 63 00:05:16,210 --> 00:05:17,410 It is very important. 64 00:05:17,420 --> 00:05:24,430 We write functions that you need to pass a parameter to to be sure that you pass all the necessary parameters 65 00:05:24,430 --> 00:05:26,110 in that function in order to operate. 66 00:05:26,500 --> 00:05:34,210 For example, if I remove the C++ from the second function, this is where the parameter so the value 67 00:05:34,210 --> 00:05:37,870 of language will not be assigned to anything. 68 00:05:38,440 --> 00:05:42,670 And now if I run it, you can see that we're printing the first function. 69 00:05:42,830 --> 00:05:46,920 OK, but once we go to the second one, we're getting the title there. 70 00:05:47,140 --> 00:05:54,370 And this is because the function requires an argument, one argument which is called language and which 71 00:05:54,370 --> 00:05:55,020 is not possible. 72 00:05:55,020 --> 00:05:57,040 And for that reason, we we're getting the error here. 73 00:05:57,490 --> 00:06:02,720 Now, obviously, since we can pass one argument, you are also able to pass a second one. 74 00:06:03,070 --> 00:06:08,050 For example, let's assign the new variable here, which is going to the task. 75 00:06:08,620 --> 00:06:10,810 So I will sign language and thus. 76 00:06:12,360 --> 00:06:21,510 That's it, so now you can see here that the first thing we need is the language, so well, I want 77 00:06:21,550 --> 00:06:25,880 shovel and the next morning, what is a task force to do a job? 78 00:06:27,030 --> 00:06:32,820 And I'm right here right function. 79 00:06:33,870 --> 00:06:36,120 So I would like to write a function in job. 80 00:06:36,960 --> 00:06:43,120 If you're on the call now, you can see that we are getting quite a function eungella, which are both 81 00:06:43,170 --> 00:06:45,000 parameters that will pass the function. 82 00:06:45,930 --> 00:06:48,920 So now since to function as a task, I can simplify it. 83 00:06:48,930 --> 00:06:52,940 Thus you close and then just refer to the right to function. 84 00:06:53,280 --> 00:07:01,500 And next week I can write language close in here just to refer to the language. 85 00:07:01,770 --> 00:07:02,850 So I'll write here. 86 00:07:04,200 --> 00:07:12,030 And in that case, even though the basis of our parameters are on different positions, this will not 87 00:07:12,030 --> 00:07:16,550 interrupt the function and you get the right parameters on the right places. 88 00:07:16,740 --> 00:07:22,230 And as you can see here, we're getting quite a function in Java, as is supposed to be.