Beginner Topic 13 of 54 Programming Fundamentals
Parameters and Arguments
Placeholders in a function definition versus actual values passed in a call.
How it works
Parameters are the names declared in a function definition, while arguments are the actual values supplied at call time. Languages offer positional parameters, keyword arguments, default values and variadic parameters that collect any number of extra values. How arguments are bound, by value or by reference, determines whether the function can alter the caller's data.
Step-by-step walkthrough
- Parameters a and b are placeholders in the definition.
- Arguments 2 and 3 are the actual values at the call site.
- On the call each argument is bound to the matching parameter by position.
- The body runs using those bound values.
- Extra or missing arguments cause an error unless defaults exist.
Where it is used
Configuring behavior, for example connect(host, port=5432, timeout=10), passing data into computations and designing flexible APIs with optional settings all rely on parameters. Keyword arguments make calls self-documenting.
Common pitfall
Mutable default arguments, such as an empty list in Python, are created once and shared between calls, causing famous bugs. Too many parameters or swapped positional arguments of the same type lead to errors; group related values in an object or use keyword arguments.
Where it fits in the course
Parameters and Arguments is topic 13 of 54 in Programming Fundamentals, rated Beginner. It follows Functions. The next topic is Return Values.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Programming Fundamentals quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Programming Fundamentals quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Parameters and Arguments?
Where do people use Parameters and Arguments?
What is the most common mistake with Parameters and Arguments?
What should I learn before this topic?
How can I practice it?
Is Parameters and Arguments hard to learn?
How long does it take to learn Parameters and Arguments?
Which topics are related to Parameters and Arguments?
What should I study after Parameters and Arguments?
Related topics
- Functions (Programming Fundamentals)
- Return Values (Programming Fundamentals)
- While Loops (Programming Fundamentals)
- Scope (Programming Fundamentals)