 Hello everyone, my name is Nikhil Gadjam working as assistant professor in department of computer science and engineering. In today's session we will see Python function. Learning outcome of this video is students will be able to declare and define a function in Python script. Syntax for writing a function in Python, so DEF space a function name and then in bracket argument list. Now argument list is nothing but the variables or the values which are passed to the function while calling the function, we call it as argument. That may be a single value or multiple values and this argument list it is not compulsion, it is optional. Either you can pass the arguments while calling the function or you cannot pass the values. DEF it is a keyword stands for definition used for defining a function. So DEF space a function name, a function name can be anything and then argument list. So this is declaration of a function, then body of the function. Remember that in Python there are no brackets available. So at the end of this function after argument list a colon is there, it is must indicating that it is a start of new block. So all the statements after this function having a same indentation belongs to this function. Next one we will see an example. Suppose example is add a two function using add a two variables or two values using the function in Python. So we will see an example we write a code for adding a two numbers using function. So this is a pyCharm, this is IDE for Python. Suppose I will declare one function called as add which is not accepting any parameters. So I will take a two number, suppose this is num1 equal to int in bracket input, then I will enter a message as enter number one and then this is num2 equal to again int again this input, then enter number two. Now this num1 I am taking a value from the user and similarly num2 I am taking a value from the user. So this message is displayed on the output screen first called as enter number one. Then input is a function for taking input from the user. By default return type is string. So I have typecasted that into the integer values. So these are the two integer value I have taken from the user. So I will add these two values and store in the result variable. So result equal to num1 plus this num2. I will print the result, print this is result equal to comma result. After this apart from this function I will call that function from outside the function. So how to call that? Just call the function name. I am not passing any arguments because this function is not accepting any values. I will execute this. I will right click here and click on run file. So it is asking number one, suppose number one is 10 and then number two. So number two is 20. So result equal to 30. Now it is a function which is not accepting any value. So how to call this function? Just function name. We will move forward now. So similarly we can pass arguments to the function while calling the function also. So same example I will take adding addition of two numbers but with parameters passing. We will remove this. So this is def add. So it accepts one integer value and another integer value sorry a and b this is colon. So result equal to a plus b and then print result comma result. So this is my function. So I will take two values from the user. Num one equal to, this indentation problem is there just a second. This is num one equal to integer then input then this is enter number one. Similarly num two equal to integer then again input enter number two. Then I am calling the function. Function name is add. For that add function now I am sending two values num one and num two. So your execution starts from this statement. So first a message will be printed on the output screen called as enter number one that will be converted into integer value stored in the num one. Similarly enter number two message will be displayed that will be converted into integer value stored in the num two. Then I am calling a function add and I am passing two values whatever entered by the user. So this function is getting called. So num one and num two these values are passed as an argument and that will be stored in a and b. Then result will be calculated a plus b then result is printed. So we will execute this. This is num one. Enter num one suppose 10 enter num two suppose 20. So result equal to 30. So this is an example for passing arguments to the function. So I have passed two arguments num one and num two to the add function. We will go for one now. You can pause the video and you can answer. Is it possible to have a function overloading in Python? You can pause the video and you can answer. Answer is yes. As we know function overloading it is a concept of object under programming where two or more functions are having same function name but different arguments that different arguments may be in terms of numbers or in terms of data types. So we will try this function overloading. Suppose I will write another function def add which is not accepting any values and suppose inside this suppose I am sending print and this is I am writing example of suppose this is function overloading. Now so these are the two functions which are having same name but these functions are accepting different types of arguments. This first function is accepting two values and second function is accepting no values or zero values. So this concept we call it as a function overloading. So how to call first function? So this is the first function call where you are passing two values to integer values. How to call the second function? Just add. So this first add function call a first function is getting called and for this second only add which is not accepting any parameters any argument the second function is getting called. You check this suppose enter number 1, 5, number 2 is 10, just a second it takes two arguments two given just a second I will remove this and we will execute this and number 1, 5 and number 2 is 10. What will be the error? Just a second def add. Just a second I will remove this. It is called as confusion or ambiguous function call where two functions it is not decided during runtime that which function is getting called. So this is called as an ambiguous situation compiler is giving error that which function is getting called that it is not deciding. This term we call it as method overloading where two functions are having same name but different arguments or different types of arguments. We will move forward. Now there is another concept in functions in Python we call it as default parameters. A non-default and default parameters may be mixed in the parameter list of the function declaration but all the default parameters within parameter must appear at the end. Now what is default arguments when you are passing arguments to the function and that value is fixed during that while declaration of the function only. We call it as default argument but there is one rule while defining the default arguments. Whatever default values are there if you are mixing the default parameters with non-default parameters in that case default parameter must be at the right hand side. Example is this one. So DEF sum range is my function name it is accepting two arguments n and m but m equal to 100 this is called as default arguments. So by default value of m will be 100. But whatever default arguments you are passing to the function that must be at the right hand side compulsory. Similarly in the second example DEF sum range n equal to 0 and m equal to 100 in this case there are two default arguments. If all the arguments are default then it is okay no problem. But default arguments values must be start from right hand side. But in the third example DEF sum range in bracket n equal to 0 and m only it is not allowed because there is only one default argument and that is n it must be appear on the right hand side. On the left hand side it is not allowed. So this is a rule of default parameter or default argument. We will see an example. Same example I will take instead of writing now DEF add a and b equal to 100. So by default value of b is 100. So I am calling that function now. If you pass now only suppose 50 and execute this result is 150 when you pass only argument 50 that will be stored in a and by default value of b will be 100. So 50 plus 100 it will be 150. You can pass two values also 50 and 200. If you check this output will be 250. So 50 will be stored in a and 200 will be stored in b. So output will be 250. So this is default argument. These are the references I have used for creation of this video. Thank you.