[MUSIC] Hi everyone. The topic we are going to study today is functions. Making functions. Making function means that making your own tool to perform specific taskers that you want to accomplish. So, concept of function if you studied mathematics, probably you know y is equal to functional f(x). It means that x are inputs. Somehow inputs are transformed into an output by this function f(x), right? That's what you remember. And we actually realize that relationship using software coding tools. So, using python, we are creating functions. Creating functions means that, again, it is creating tools that you are going to use in your software programming. So,actually this is a key component of coding. Later at the end of this course, you will learn making classes. Two are important building blocks of coding. One of them very important basic coding tool is making functions. Once you make a function, you can use it for producing something, why? Repetitively, so often a function is used with control statements. There are three types of functions. One is built in functions. You already know them, right? Like length, length, linear length type function. Those are already created by Python. It is provided as a power standard library. So you can use many built in functions already created by somebody else. But now, you should be able to make your own functions, that is user-created functions. Today we study that topic. There is another type of function, anonymous function, especially lambda function is a case of anonymous function. Anonymous function means there's no name. That's the only difference, and it is often years later, I will explain it. The lambda function, not here. Now, let me briefly introduce basic syntax of a function. Function, in order to make a function, you need to use the keyword definition, def, right? Def here. D means definition, which is followed by function name. You need to use lower case for function name, especially the first letter of function name better to use lower case. You can also use on the bar as a part of function name. So for example, here's a circle on the bar area and circumference. So by connecting our multiple worlds, you can create a function name. But it is a mandatory rule. But you are recommended to use lower case is for function name. Capital letters are used for class names. So, by just looking at name of an object, we can need to understand this is or function. This is a class. So try to use under lower case letters or for function names. And you are also recommended to use or Docstring immediately after the definition headline. So why? Because the Docstring is used for explaining what the function is for. So it is a way of explaining the usage of function. By providing Docstring later, you can understand what the function is for. Otherwise while coding you are creating so many functions. Sometimes you don't know, you cannot identify what that is for based on name. So, in that case you look into Docstring then other people can also understand the role of a specific function. We'll also study random number generation and the ways of importing libraries in this module. Now, let me give you an example of user-created function. Here is our cell, the first line is import math. Importing math. Math is a module provided in standard library. It means that it is a part of standard library. But in order to work in your working space, sometimes you need to bring that module in your working space. So math is not existing in your working space. So you need to bring that in your working space in order to use it. So, it is a way of importing, bring a tool into your working space, that is import math. In math, module, there are many functions. One of the functions we are going to use is pi. Pi is 0.14 equals infinity. But you don't need to type the number, simply you use pi object already created in math module. So, a function start with this definition keyword, def. And a blank comes, and then name of function object, circle. I gave circle, so you can give different name if you want. And in parenthesis, this is like f(x) x input, radius will be the input. I am providing radius information then the circle, then this step. Function transforms that radius information into outputs. The first headline always end with a color. And then following this headline, here's a Docstring, right? So this explains the usage of this function, calculates area and circumference of a circle with a radius. So here the input variable radius, it don't have to be radius. You can use any variable name like x or y, z, any variable name you can expect. I used radius because it is easy to understand because we are going to use that information in calculating area and circumference. Then the function returns the area pi multiplied by the radius squared. That is the area a variable calculating area, formula of calculating area of a circle. Then 2 times pi multiplied by radius, 2 pi r. That is a formula calculating circumference of a circle. So, this function that you create takes one input radius information and returns two outputs. One is a variable circle, the other one is a circumference of a circle. So one input, two outputs. The function transforms input information into outputs. It's like cooking, you have some ingredients. With the ingredients you make bread, food, pizza or all kinds of food you can produce. So that food producing process is like a function. So once you make a function, we need to create objects by running the cell. Then circle object is created. Now, we can code it, so circle and I'm providing radius 3 information. Then what happens? Wow, so area is 28.27 and circumference is 18.84. There are many decimal points. So, now we can do similar thing by inserting function in f string, f string that we already started, right? So, x in the next cell, x is defined or signed by three. Then print function comes. So the area and circumference of a circle is x centimeter radius, a circle x this one. We already know the circle function takes one input returns two outputs. Then this is the index of the output. This means that index 0 is first output. It means that area information will be printed here, right? And we already studied f string, the 2f. Above, there are so many decimal points, but we are confining decimal points reading 2, 2f. Then centimeter squared and circle index one. Circumference information will appear here and decimal point is 3. Now, let me execute this cell. Then the area of circumference of a circle with 3 centimeter radius are 28.27 centimeters squared and 18.850 centimeters. So it is nicely presented because I controlled the decimal point using f stream. Now, I already explained with Docstring, you can explain the usage of your a function that you created. It means that how can you look up function information? The circle, that is the name of objects, so simply add question marks and enter. Then what happens? It returns all the information of the circle object. Signature, this is the headline part. Circle, it takes radius as an input and here's Docstring. This is what I already typed in, calculate area and circumference of a circle with a radius. And this is the while location and type is data or object type is function. So, you can share this function with others then others can check whether what circle function does by simply adding question mark. And before finishing this first video clip, let me give you a review question. True or false? Functions are used to perform specific taskers. Right, that's exactly what I explained, true.