What Is an Argument in Python?
An argument in Python is a value you pass to a function when you call it.
This helps the function work with real data. For example, a function can greet different people, add different numbers, or print different messages based on the arguments you give it.
A common beginner confusion is the difference between arguments and parameters:
- Parameters are the names written in the function definition.
- Arguments are the actual values passed into the function call.
def greet(name):
print("Hello", name)
greet("Sam")
"Sam" is the argument. It is the value passed to the function.
Simple definition
- An argument is a value you give to a function when you call it.
- The function uses that value while it runs.
- Arguments go inside the parentheses after the function name.
For example:
print("Hello")
Here, "Hello" is the argument passed to print().
Argument vs parameter
This difference is important when you start writing your own functions.
- A parameter is the variable named in the function definition.
- An argument is the actual value passed to that function.
- In
def greet(name),nameis a parameter. - In
greet("Sam"),"Sam"is an argument.
Example:
def greet(name):
print("Hello", name)
greet("Sam")
What each part means:
nameis the parameter"Sam"is the argument
If you want a fuller explanation, see function parameters and arguments in Python and what is a parameter in Python.
Why arguments are useful
Arguments make functions flexible.
- They let one function work with different values.
- They make code more reusable.
- They help avoid repeating similar code.
Example:
def greet(name):
print("Hello", name)
greet("Sam")
greet("Ava")
greet("Leo")
Output:
Hello Sam
Hello Ava
Hello Leo
The function stays the same. Only the argument changes.
Common types of arguments beginners see
Positional arguments
A positional argument is matched by order.
def add(a, b):
print(a + b)
add(3, 5)
Output:
8
Here:
3is passed toa5is passed tob
If you swap the order, the values go into different parameters.
Keyword arguments
A keyword argument is matched by parameter name.
def greet(name, message):
print(message, name)
greet(name="Sam", message="Hello")
Output:
Hello Sam
Keyword arguments can make code easier to read. Learn more in default and keyword arguments explained.
Default arguments
A parameter can have a default value. If you do not pass an argument for it, Python uses the default.
def greet(name="friend"):
print("Hello", name)
greet()
greet("Sam")
Output:
Hello friend
Hello Sam
How to read a function call
When you see a function call, read it in this order:
- Look at the function name first.
- Then look inside the parentheses.
- The values inside are the arguments.
- A function can have zero, one, or many arguments.
Examples:
print("Hi")
len("apple")
sum([1, 2, 3])
In these calls:
"Hi"is an argument toprint()"apple"is an argument tolen()[1, 2, 3]is an argument tosum()
If you are new to functions, it also helps to read what is a function in Python.
Beginner examples to include
One argument passed to a print-like function
print("Python is fun")
"Python is fun" is the argument.
Two arguments passed to an add function
def add(a, b):
print(a + b)
add(10, 20)
Output:
30
10 and 20 are the arguments.
Keyword argument example
def show_user(name, age):
print(name, age)
show_user(age=25, name="Maya")
Output:
Maya 25
The arguments are still values, but they are passed by parameter name.
Function call with no arguments
def say_hello():
print("Hello")
say_hello()
This function call has no arguments because nothing is inside the parentheses.
Common mistakes
Beginners often run into these problems:
- Mixing up arguments and parameters
- Thinking the variable in
defis the argument - Passing arguments in the wrong order
- Forgetting required arguments when calling a function
- Using a keyword name that does not exist in the function definition
Example of a missing argument:
def greet(name):
print("Hello", name)
greet()
This causes an error because name needs a value.
If you see this problem, read how to fix TypeError: missing required positional argument.
Useful checks while learning:
help(print)
help(len)
print(type("Sam"))
print(len.__defaults__)
These can help you inspect built-in functions and understand what kind of values you are passing.
FAQ
What is the difference between an argument and a parameter in Python?
A parameter is the name in the function definition. An argument is the value passed when calling the function.
Can a function have more than one argument?
Yes. A function can accept multiple arguments if it is defined with multiple parameters.
Can a function have no arguments?
Yes. Some functions are called with empty parentheses.
Are keyword arguments and positional arguments both arguments?
Yes. They are two common ways to pass values to a function.
See also
- Function parameters and arguments in Python
- What is a parameter in Python?
- What is a function in Python?
- Default and keyword arguments explained
- How to fix
TypeError: missing required positional argument
Next, learn how parameters and arguments work together in real function examples.