There are two main types of functions in Python. The first one is called built in functions, which are those functions that are already present in Python, and you can use them by writing their names. The syntax of this type of function is that you write down the name of the function, followed by open parentheses, then an argument and then close parentheses. An example this one includes print function. So you write down print, and open close parentheses and in between you write down an argument, the argument could be a string, like hello world, in a string format, or an integer or a mathematical operation. There is more to it.
And we are going to go through all of the functionalities of print function in later videos. There are other built in functions in Python. These include count function, Len function, range, string, int, float, input, and many others. So let's try to have a look at print function. So we have a variable here, x equals two, y equals three, and z equals five. So we can print them out by writing down print, open parentheses, x comma y comma z comma s EP, which is a separator, equals and in between quotations, we write down a sign.
We can also print out all of them together, like 235 You can do mathematical operations like x plus y per seat, and it will sum them up. When you press enter, it would be 10. You can also do conversions of the variables. So, for example, you convert X to string, it will show you x in a string format iview some two variables that have been converted to string like print, str x plus STr y bit say, it will actually put them next to each other like two and three. So this is not 23 because this that was a trick. However, if you sum them up, it would become five, because the sum of two and three is five.
So that was built in function in Python. The second type of functions in Python is called custom made functions. In which you create your own functions, depending on your needs. The syntax of this type of function is that you write on def, short for define to define a function, and then the name of the function that you want. It could be any name, followed by open parentheses, and variables, then close the parentheses, and colon. Then after that, you indent arguments, you write down all arguments, and then you write down return, open parentheses, and the variable that you would like to return close parentheses.
So let's create a function that can square a number. You're right on deaf and named like square, open parentheses and a variable, close parentheses, colon and press enter. Then, declare another variable let's say s q equals x mult by x, square it then return sq. Press Enter to use this you write down square, open parentheses a number to pass the number to the function, then it was correct. You can test this on any kind of variable or any kind of number, and it will return this square value. The number could be float or integer.
So that's how you create a function that can perform something for you.