What are functions? At the most basic level, you can think of functions as a set of instructions that take an input and return and outputs. For example, the primary task of the print function is to print a value. This value is usually printed to the screen and it's passed to the print function as argument. In the example we have here, the string hello world is the value passed to the print function. By the end of this video, you'll be able to declare a function in Python, pass data into a function, and return data from a function. A Python function is a modular piece of code that can be re-used repeatedly. You've used some Python functions already in this course, such as print and input. Both are functions and each one has a specific task or action to complete. The input function will accept parameters too, but will also accept input from the user. So how do you declare a function? A function is declared using the def keyword followed by the name and task to complete. Optional parameters can also be added after the function name within a pair of parentheses. Here is an example of creating a function to add two values. Type the def keyword followed by the function name of sum, then enter x and y as parameters. Finally, enter return x plus y as the task to complete. I'll now give a practical demonstration of functions, how to declare them, how they're used, and how they can also simplify your code by putting it into a reusable structure. Let's start with a short example that explains how to calculate a tax amount for a customer, based on the total value of that bill. I'll start by declaring two variables. I type the first variable called bill and I assign it the number, let's say, 175.00. I know this is going to be a datatype known as floats because I'm using decimal points as is the norm for currency. The second variable is the tax rate, which is the percentage tax rate that should be applied to the bill, so I put in 15. Then what I want to do is calculate the amount of tax for the bill itself. What I do is add this into another variable called total tax. I then do the calculation, which is the bill multiplied by the tax rate and then divided by 100 to get a dollar amount. To output the value, I print the total tax and pass the total tax variable and then run the program. Total tax is 26.25, which is 15 percent of 175. In the real-world, the bill value will be different for each customer and the tax rates may also change. Updating each variable every time is inefficient. To overcome this problem, I'll create a reusable function. To start creating a function, I use a define command or def for short. Then I'll give it a name that relates to the task it's carrying out. In this case, it's going to be calculate tax. With functions, you can pass in arguments. The purpose of that is to make it more dynamic. Consider the arguments that I need to take in. I'll take in a bill, which would be the total value of the bill itself, and then also a tax rate. Then like I've done before, I'll calculate the total tax by taking the bill, multiplying it by the tax rate, and then dividing it by 100. Then I do a return, write bill in parenthesis, multiply it by tax rate, and divide by 100. Now I can remove the declaration I made earlier for the variables and the calculation. With a function, if you run the current code as is, it will come back with nothing because a function is only ever run when it's actually being called. I'll demonstrate this. If I do a print, I can calculate tax and then I pass it as I've done earlier. One hundred and seventy five is the total bill and then the tax rate will be 15. I'll also put in just the total tax and then click on "Run", and the total tax is 26.25. If I want to change the rate, I can reuse the same function, total tax. I'll call the function, again, calculate tax. I'll give it a different value for a bill, say, 164.33. This time I'll change the tax rate to 22 percent. Clear the screen, and then click on "Run" and my total tax for the second item is 36.1526. To clean the outputs up a bit and make it more visually appealing, I'll put in a round function which allows control of the number of decimal places that I want returned. In this case, I'll do two and then rerun the code. This is a lot neater with 36.15. One of the nice things about a function is that you can update it once and any part of the code that calls that function will get those changes as well. In this video, you've explored basic functions in Python, how to declare functions, and pass and return data to and from them.