What Is a Parameter in Python?
A parameter in Python is a variable written inside the parentheses of a function definition.
It acts like a placeholder. When you call the function later, Python gives that parameter a value.
This page focuses on the basic idea:
- what a parameter is
- where it appears
- how it is different from an argument
It is not a full guide to writing functions. If you want the bigger picture, see Python Functions Explained.
Quick example
def greet(name):
print("Hello", name)
greet("Mia")
In this example, name is the parameter. "Mia" is the argument passed to the function.
Output:
Hello Mia
Page purpose
This page answers a common beginner question: what is a parameter in Python?
It keeps the topic narrow and practical:
- a clear definition
- where parameters appear
- simple examples
- the difference between parameters and arguments
Simple definition
A parameter is a variable listed inside the parentheses when you define a function.
It is a placeholder for a value the function will receive later.
Parameters are useful because they let one function work with different input values instead of being hard-coded for just one case.
Where parameters appear
Parameters appear in the function definition line.
They come:
- after the function name
- inside the parentheses
Example:
def add(a, b):
return a + b
In this function:
ais a parameterbis a parameter
Both names are available as variables inside the function.
Parameter vs argument
This is the part that confuses many beginners.
- A parameter is the name in the function definition
- An argument is the actual value passed when calling the function
Example:
def greet(name):
print("Hello", name)
greet("Mia")
Here:
nameis the parameter"Mia"is the argument
A simple way to remember it:
- parameter = the variable in the function
- argument = the real value you send into it
If you want a fuller comparison, read Function Parameters and Arguments in Python or the glossary page What Is an Argument in Python?.
Why parameters are useful
Parameters make functions more reusable.
Without parameters, you often have to repeat similar code. With parameters, the same function can work with different data.
For example, this function can greet many people:
def greet(name):
print("Hello", name)
greet("Mia")
greet("Leo")
greet("Ava")
Output:
Hello Mia
Hello Leo
Hello Ava
The function code stays the same. Only the argument changes.
Basic examples to include
One parameter example
def show_color(color):
print("Color:", color)
show_color("blue")
In this code:
coloris the parameter"blue"is the argument
Output:
Color: blue
Two parameter example
def add(a, b):
print(a + b)
add(3, 5)
In this code:
aandbare parameters3and5are arguments
Output:
8
Example showing parameter names receive passed values
def introduce(name, age):
print("Name:", name)
print("Age:", age)
introduce("Mia", 12)
When the function is called:
namereceives"Mia"agereceives12
Output:
Name: Mia
Age: 12
This shows that parameter names become variables inside the function after values are passed in.
Important beginner notes
Keep these points in mind:
- A function can have zero, one, or many parameters
- Parameter names are variables used inside the function
- A parameter only gets a value when the function is called
Example of a function with no parameters:
def say_hello():
print("Hello")
say_hello()
Output:
Hello
So parameters are common, but they are not required for every function.
Common confusion to address
Beginners often run into the same misunderstandings.
Mixing up parameter and argument
People often use these words as if they mean exactly the same thing.
They are closely related, but not identical:
- parameter = name in the definition
- argument = value in the call
Thinking the parameter already has a value
A parameter does not automatically have a value before the function is called.
For example:
def greet(name):
print("Hello", name)
Here, name is just a placeholder until you call the function with something like:
greet("Mia")
Forgetting to pass required arguments
If a function expects a value and you do not pass one, Python usually raises a TypeError.
def greet(name):
print("Hello", name)
greet()
This causes an error because name needs an argument.
If that happens, see TypeError: missing required positional argument (Fix).
Common mistakes
These are common causes of confusion around parameters:
- Using the words parameter and argument as if they mean exactly the same thing
- Calling a function without passing all required values
- Assuming parameter names outside the function are automatically connected to inside names
- Confusing parameters with return values
For example, these names do not need to match:
def greet(name):
print("Hello", name)
person = "Mia"
greet(person)
This works because the value of person is passed into the parameter name.
Output:
Hello Mia
The outside variable is person, but the parameter inside the function is still name.
FAQ
What is a parameter in Python in simple words?
It is a variable in a function definition that receives a value when the function is called.
Is a parameter the same as an argument?
Not exactly. A parameter is in the function definition. An argument is the value passed to the function call.
Can a Python function have no parameters?
Yes. Some functions do not need any input values.
Can a function have more than one parameter?
Yes. You can define multiple parameters separated by commas.
What error happens if I forget an argument?
You often get a TypeError saying a required positional argument is missing.
See also
- Python Functions Explained
- Function Parameters and Arguments in Python
- What Is an Argument in Python?
- What Is a Function in Python?
- TypeError: missing required positional argument (Fix)
Next step: learn how parameters and arguments work together in real function calls.