All right.
So welcome to this brand new section where we're going to take a look at functions
and so far so good.
We've actually been working with quite a
number of prebuilt functions within Python.
So functions like the print input range and so on,
they all perform a particular kind of operation.
However, what if we wanted to create our very own custom functions?
How can we do that well to do? So
we are going to have to
define the name of the function first of all
and then decide whether or not that function
is going to accept what we call parameters.
And then we can also say, OK,
this function will add these numbers or is going to do something.
And then finally, we can choose to return a value within that function. So
it's going to be something like this. OK?
You will have the def which is going to be the function to define
the name of the function. And then you can, you can choose to have parameters
inside of that function.
OK?
And then
we'll have the function body.
So you know, add A plus B, add this,
do this divide this check to see if this loop is true, you know, stuff like that,
basically whatever the, the function will do.
And then finally,
we can then choose to return
a value, which by the way,
this is going to be optional,
we don't always have to return a value whenever we are creating our own function.
Let me give you a very, very basic example.
So let's say for example, we wanted to create
a function
that will print
the words hello world.
All right,
we can say DF and then I can call my function greet.
So the name of my function is going to be
greet and then I can add my brackets at the colon
and then enter,
by the way, notice that I haven't added any parameters inside of the
brackets in here.
Parameters are optional.
However,
I'm gonna come in right now and then define what the function will actually do.
So I'm gonna say print.
Now,
I'm going to provide the words hello
world.
And now all I would have to do
is to simply call the function.
And how do I do that? I'm gonna say greet
and then the packets.
And if it is,
so now if I was to run the program, there you go.
It simply says hello world.
So once again, we started off by giving the name
greet to our function.
And then we're now told what the function should do.
The function should print Hello world. Whenever we call or use that function.
And then right here we simply call the
function by simply saying greet and then in brackets
and
there you go.
So this right here is
one of the most basic kinds of functions we can create.
But that's it, German.
Even next video where we'll now begin to take a look at function parameters
and arguments. I'll see you then.