Function Arguments and Parameter Variables
00:00 In this lesson, you’ll explore the relationship between function arguments and parameter variables. In Python, parameter variables are considered local variables, meaning they have local scope. The name only has meaning inside the function.
You can also get the dictionary of everything in global scope using the
globals() function. To see how it works, you can create a small function that creates a local variable and calls the
locals() function. I’ll just do this interactively.
01:46 Remember, parameter names are bound to the objects passed as arguments on function entry in Python. And again, to illustrate one more time that as arguments are passed to functions parameters create additional references to the object passed, you can write a similar function to track reference counts instead of bindings.
02:18 We’ll pass one argument to it—mainly, the one whose references we wish to count. And we will get the reference count for that object passed. First, let’s just get the reference count for the object I’m going to use, but before we actually use it as an argument to the function.
So now you’ve seen when an argument is passed to a function, the parameter name is bound to the same object. You can see that binding in the locals dictionary and you can see the additional reference to it using
Become a Member to join the conversation.