Hi, everyone, in this section, we're going to talk a little bit more about how to structure your
Python code and actually put in operation way easier because, you know, when your lines of code increase,
you actually need to have some structure behind your code.
And you cannot simply just write a line after line without thinking for that reason.
Today, we're going to concentrate on different functions, classes and structures that will help to
structure your code and use it way easier.
This will add more structure to your code and make it more professional.
So let's start by digging into what are actually the functions and how you can create function in Python
in order to help your code be more useful.
So here I am in my IT and I will create the new Python project in which we're going to add our data.
So let's create next python functions and then finish.
So here you have your project and I will create and say this project project by Dev Module.
So let's call the package Python one two.
True.
Let's create a function in the name of the module.
Will the quote unquote.
OK, so you can see that now we're here for our module created and let's start creating functions.
So first of all, how will you find functions in Python?
So in Python you define a function also by just three letters, D.F. space.
And this is how you define the function that in our case, our quick function, that we will assign
a task to the user and you see what they mean.
So when writing a function after the def keyword, you need to write the name or the function.
So the name of dysfunction will be holer underscore usque and then you write to Brackett's, that's
it.
And automatically it gets to lots of Start-Up, so that's fine.
So after you create the name of the function, you should go to the inner innovational in order to write
what is going to be the speech and say just function.
So usually between just break ins you can pass parameters or you can choose not to pass any parameters
to the function.
But later on, I'm going to talk more about this as well.
So let's our functional print task.
So your homework does not hold up and then print and then the task.
So the task will be declared eight variable in item.
OK, so this is the function and now you can call the function.
So in order to know when the function success is needed, I want this to sentence's print.
Start and then print and OK.
So between these two statements, I will call the function and how we do this by simply defining the
name of the function.
So homework task in the brackets.
OK, this is how we are calling the function from the call.
Now I will run the project and you can see here that we are getting all the messages, your homework
task declare a variable in Python.
So this was the most simple case of function because here you do not need to pass any parameters.
You simply called the function name and basically what was written inside the function to start working
towards the two print statements.
Now, the function also can give parameters.
For example, if I write here language, OK, this means that in order to make this function work,
we need to pass a variable that is going to be assigned to language in our function, or we're going
to use the language in order to refer to the variable in how this is done.
So I will remove them from here and I will simply write to declare a variable loss language.
OK.
And then when you're calling the function here in the brackets, you're going to pass the variable that
you would like to be displayed inside of code.
So this means every time a call the function, you can change the result of dysfunction depending on
the input parameters that you up inside it.
So I will write here,
even though we're doing five.
Of course, our challenge here is you will see that when I run the top, you're getting your Java.
Now, if I call the function again, but this time I write C++, then you'll see that we're going to
have two results.
And in the first one, we're going to Taba.
In the second one, we're using C++.
It is very important.
We write functions that you need to pass a parameter to to be sure that you pass all the necessary parameters
in that function in order to operate.
For example, if I remove the C++ from the second function, this is where the parameter so the value
of language will not be assigned to anything.
And now if I run it, you can see that we're printing the first function.
OK, but once we go to the second one, we're getting the title there.
And this is because the function requires an argument, one argument which is called language and which
is not possible.
And for that reason, we we're getting the error here.
Now, obviously, since we can pass one argument, you are also able to pass a second one.
For example, let's assign the new variable here, which is going to the task.
So I will sign language and thus.
That's it, so now you can see here that the first thing we need is the language, so well, I want
shovel and the next morning, what is a task force to do a job?
And I'm right here right function.
So I would like to write a function in job.
If you're on the call now, you can see that we are getting quite a function eungella, which are both
parameters that will pass the function.
So now since to function as a task, I can simplify it.
Thus you close and then just refer to the right to function.
And next week I can write language close in here just to refer to the language.
So I'll write here.
And in that case, even though the basis of our parameters are on different positions, this will not
interrupt the function and you get the right parameters on the right places.
And as you can see here, we're getting quite a function in Java, as is supposed to be.