Functions functions functions there are two types of functions.
Bilstein and custom building functions are functions that have already been created by Python authors
and are to use from Python programmers which is always a print function.
It's an example of for beauty in function
but in this lecture we're going to talk about Kasa functions and custom functions are super useful.
I'll referred to custom functions as just functions from now on.
So a function is an algorithm but even by us that computes in alterable given a certain input.
The key benefit of function is that.
Or you can write a function only once but you can use it as many times as you want by just calling it.
Which is very simple.
Here is how to write a function in Python.
I'm going to create a function here that calculates the coast of potatoes unit price and the amount.
So we use the word keyword def to tell Python that we are about to define a function and after that
we choose a name for our function.
I will name my faction but take two cost.
Once we are either a function name we said the input parameters for the function and we can now write
what function will compute and what it turns out.
In this case we want to compute the cost of potatoes given the price on them and so close equals potato
price dimes and moaned and we also want let's say to print out the potato type.
Now we are printing all the potato type but we also want to return the calculated closed where the function
is executed later.
We can either do it using the print function or we can use the return keyword.
I'm using the return keyword here and see now how easy it is to call the function once we have created
it.
So potato goes and we write the values which are called attributes.
Now notice that we are imputing values for each of the parameters in the given order and what we get
is a printed potato type and the computed cost.
You can now execute the function as many times as you want using different values.
And the last thing to mention here is that we are old fashioned in the Python console as I have told
you before.
This is a platform for testing.
If we close I on we will lose our function the Phoenician will not be able to call it anymore.
So normally we want to store our function in a script for later use.
In that case we have to write it in a dot by script.
Once we do that we can't really use the function in the future.
So that was how to define and call a function.