 Whenever you have a Python function, all the names of the parameters and the variables that you define inside that function are called local variables. They belong to that function and nobody else can get to them. Consider these functions f and g. They both have a variable called z. The z that's used on lines 2 and 3 is local to function f. It belongs to f. The z that's used on lines 8 and 9 belongs to g. And this z here on line 13 is a variable that's been declared outside of any function. All three of these z's are totally independent of one another. It's as if each function is its own private universe, and this is exactly what we want, because it means we can use any variable names we want in our functions with an absolute guarantee that they won't conflict with the variables defined by anyone else in any other function. Parameters are also local. The x and y on line 5 are completely independent from the x and y that are used on lines 11 and 12. An important point to note is that the parameters get a copy of the arguments. The arguments themselves don't change. Let's step through this program in the debugger to see what's going on. We'll step over the definitions of f and g, and also the assignment of 2 to x and y to 3. They show up here in our variable window. And now let's go into the call to f. x is 2, y is 3, and when we make the call, we get a brand new window. A and B are parameters that have been filled in with copies of x and y, the 2 and 3. And 2 times 3 is 6, plus 3 is 9, and that is assigned to the local variable z. When we return z, that window disappears. The parameters and the local variables are gone until we call f again. All we have is the return value of 9, which gets assigned to z. And so now we have z here from line 13, which has the value 9. Now let's look at the call to g on line 14. We'll step into it. x is 2, and y is 3. And when we make the call, again, we get a new copy of the variables x and y. This x and y are totally independent of this x and y, and I'll show you why. If I step over this line, x plus equals 5, the local variable x becomes 7. The original argument x remains unchanged. Similarly, when I say y is y times 3, the local variable becomes 9, but our original argument stays unchanged. And when I execute this line, I get a local variable z 63, which has nothing to do with our global variable z that's been defined in our main program. And again, when I return z, these local x, y, and z all disappear. And what's left is the return value, which gets assigned to w, our variable at the main area. And when I print z and w, I get 9 and 63. Many beginning programmers think you have to name the parameters the same as the argument variables, as we did in line 14 when we had x and y here, and we named them x and y here. But there's no law about that. Remember, the parameters are placeholders, and they can be filled in with any sort of arguments. Here in line 16, I'm using z and w and passing those in as the arguments for the placeholders x and y. On line 17, I'm not using any variables at all. I'm just passing raw numbers 30 and 4 in to x and y. This means you can't guarantee that the parameter names will always match the variable names that you use in the call. The important point here is that the variables in a function are local. No function, or your main program either, can reach into another function to look at its local variables. In general, the way you send data to another function is through its parameters, and you send data back to the caller via return. However, a function can reach outside to look at a variable that has been defined previously. Consider this program that has two functions, both of which need to know the current tax rate. While I could have put the tax rate definition into both of my functions individually, that's a lot of duplication, and if the tax rate ever changes, I'd have to change it both in line 4 and in line 9, which could lead to unexpected errors. So instead, what I'm going to do is I'm going to define tax rate here in line 1 before I define any of my functions. Because it's been defined here outside, now all my functions can access it. You'll notice by the way that I've used all capital letters for the definition of this variable. This goes counter to what I usually do, which is all lowercase. By convention, when you see something in all uppercase, programmers know that's supposed to be treated as a constant. You're supposed to set the variable once and never modify it afterwards. Let's see how these global variables work. Let's debug this script. The tax rate is going to be set to .7. We'll skip over our definitions. And now let's go into the cell call. 5 works out to 5. 20 is 20. And now what we have is the price and the quantity, which are going to be copies of the 5 and 20 from our main program. And let's go and step into this. The price is a local variable. It's 5. Quantity is a local variable because it's a parameter, and it's 20, which works out to 100. And now we need 1 plus tax rate. Tax rate isn't defined here, but because it's global, because it's already been defined outside of our function, Python can look up and outside the function to get the 0.07 and all is well with the world. We return the result as 107, and the rest of the program would continue as normal. The same thing would happen if we went into buy. 5, 20, and 0.05 become the parameters, discount, price, and quantity. And now as I evaluate this whole expression, I'm going to eventually need the tax rate. And again, it will get my global value here of 0.07 and do all of the calculations and return that result. Remember I said that programmers see all capital variable names, and that's a constant, and they know they're not supposed to modify it? Well, what if I did want to modify tax rate inside one of my functions? The answer is it can be done, but don't do that, and I'm not going to show you how to do it because it's bad programming practice. It's not a good idea to allow all your functions to trample all over global variables, because if cell were to change the tax rate globally, then when I went to go and buy, I'd have a different tax rate than the one I expected, and things would get really bad. So here's the summary of the whole video. Parameters and the variables that you define inside a function are local. They exist only as long as the function is doing its job. The moment the function concludes and returns, the parameters and the local variables disappear until the function is called again. You can define variables outside all your functions, and those will be globally accessible for reading only to your functions. Use global variables like this only for constants that many functions will need.