The Difference Between Parameters and Arguments
When defining and calling functions, it's easy to confuse parameters and arguments.
In this lesson, we'll take a closer look at the difference between parameters and arguments.
Parameters
Parameters refer to the variables used when defining a function.
def add(x, y): return x + y
In the example above, x and y are parameters of the add function.
When a function is called, the parameters are initialized with the values passed, and are used within the code block.
Arguments
Arguments are the actual values passed when calling a function.
# x, y are parameters def add(x, y): return x + y # 3, 5 are arguments result = add(3, 5) # 8 print(result)
In the code above, 3 and 5 are arguments in the call add(3, 5).
When the function is called, arguments are passed to the function's parameters and are used inside the function.
In summary, parameters are the variable names in a function definition, while arguments are the actual values passed when calling the function.
Parameters refer to the actual values passed to a function.
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help
Code Editor
Execution Result