What Are Arguments in Python? Absolute Beginners Tutorial

Arguments are the values you hand a function when you call it. Without them, functions would be isolated — doing the same thing every time with no way to accept input from the outside. Once you understand how arguments work, you unlock the ability to write reusable, flexible code that can handle many different situations from a single function definition.

When you write a function in Python, you define what inputs it expects. Those expected inputs have names — those are called parameters. When you actually call the function and pass real values in, those real values are called arguments. Python gives you several ways to pass arguments, each with its own rules and use cases. This tutorial walks through all of them from the ground up.

Parameters vs. Arguments

The words "parameter" and "argument" are sometimes used interchangeably, but they refer to different things. A parameter is the name listed inside the parentheses when you define a function. An argument is the actual value you supply when you call that function.

python
# 'name' is a PARAMETER — it lives in the definition
def greet(name):
    print("Hello,", name)

# 'Alice' is an ARGUMENT — it is the real value passed at call time
greet("Alice")

When Python runs greet("Alice"), it assigns the argument "Alice" to the parameter name inside the function. The function then has access to that value through the name name.

Note

The official Python documentation uses "argument" for the value passed in a call and "parameter" for the name in the definition. Keeping this distinction in mind helps when reading error messages — Python will tell you if you passed the wrong number of arguments.

code builder click a token to place it

Build a function definition that takes one parameter called city and prints it. Click tokens in order:

your code will appear here...
city show_city ( def return ) :
Why: A function definition starts with def, followed by the name, then an opening parenthesis (, the parameter name, a closing parenthesis ), and a colon :. The keyword return is not part of the function header — it belongs inside the body.

Types of Arguments

Python recognizes four main types of arguments. Each one controls a different aspect of how values get matched to parameters when you call a function.

Positional Arguments

Positional arguments are the most common kind. Python matches them to parameters by position — left to right, in the order they appear. If a function expects two positional arguments and you pass three, Python raises a TypeError.

python
def describe_pet(animal, name):
    print(f"I have a {animal} named {name}.")

# Positional: 'dog' goes to animal, 'Rex' goes to name
describe_pet("dog", "Rex")
# Output: I have a dog named Rex.

# Swap the order and the meaning changes completely
describe_pet("Rex", "dog")
# Output: I have a Rex named dog.
Watch Out

With positional arguments, order is everything. Python does not know what you meant — it only knows what position each value was given. A misplaced argument will not raise an error; it will just produce wrong output silently.

Keyword Arguments

Keyword arguments let you name each value explicitly when calling a function. Because you supply the parameter name, order no longer matters. This makes calls to complex functions much easier to read and harder to get wrong.

python
def describe_pet(animal, name):
    print(f"I have a {animal} named {name}.")

# Keyword arguments — order does not matter
describe_pet(name="Rex", animal="dog")
# Output: I have a dog named Rex.

# Mixing positional and keyword (positional must come first)
describe_pet("dog", name="Rex")
# Output: I have a dog named Rex.

Default Arguments

A default argument provides a fallback value for a parameter. If the caller does not pass a value for that parameter, Python uses the default. Default parameters are written in the function definition using an equals sign. They must always appear after any parameters that have no default.

python
def greet(name, greeting="Hello"):
    print(f"{greeting}, {name}!")

greet("Alice")              # Uses the default greeting
# Output: Hello, Alice!

greet("Bob", "Good morning") # Overrides the default
# Output: Good morning, Bob!
Pro Tip

Never use a mutable object (such as a list or dictionary) as a default argument value. Python creates the default once when the function is defined, not each time it is called. Using a mutable default can cause subtle bugs where data from one call leaks into the next. Use None as the default and create the object inside the function body instead.

Here is a reference comparing the three argument types you have seen so far:

How it works
Matched to parameters by position, left to right
Example call
describe_pet("dog", "Rex")
How it works
Matched by parameter name; order does not matter
Example call
describe_pet(name="Rex", animal="dog")
How it works
Defined in the function header; used when caller omits the value
Example definition
def greet(name, greeting="Hello")
spot the bug click the line that contains the bug

The function below has a default argument in the wrong position. Click the line you think is wrong, then hit check.

1 def order(quantity=1, item):
2 print(f"Ordering {quantity} of {item}")
3
4 order("apples", 3)
The fix: Move quantity=1 after item so the definition reads def order(item, quantity=1):. In Python, parameters with default values must always follow parameters without defaults. Placing a default parameter first causes a SyntaxError.

*args and **kwargs

Sometimes you do not know ahead of time how many arguments a function will receive. Python handles this with two special syntax patterns: *args for a variable number of positional arguments, and **kwargs for a variable number of keyword arguments.

*args — Variable Positional Arguments

Placing a single asterisk before a parameter name tells Python to collect all remaining positional arguments into a tuple. The name args is a convention — the asterisk is what matters syntactically.

python
def total(*numbers):
    result = 0
    for n in numbers:
        result += n
    return result

print(total(1, 2, 3))        # 6
print(total(10, 20))         # 30
print(total(5))              # 5
print(total())               # 0

Inside the function, numbers is a regular tuple. You iterate over it, index it, or pass it to other functions just like any other tuple.

**kwargs — Variable Keyword Arguments

Placing two asterisks before a parameter name tells Python to collect all extra keyword arguments into a dictionary. Each key is the argument name the caller used; each value is what the caller passed.

python
def show_profile(**details):
    for key, value in details.items():
        print(f"{key}: {value}")

show_profile(name="Alice", role="developer", level="junior")
# Output:
# name: Alice
# role: developer
# level: junior

Combining All Four Types

You can mix all four argument types in a single function definition. The rule is that they must appear in this specific order: regular positional parameters first, then *args, then keyword parameters with defaults, then **kwargs.

python
def build_report(title, *sections, separator="---", **metadata):
    print(f"Title: {title}")
    for section in sections:
        print(separator)
        print(section)
    print("\nMetadata:")
    for key, value in metadata.items():
        print(f"  {key}: {value}")

build_report(
    "Q1 Review",
    "Sales increased 12%",
    "Costs held steady",
    separator="===",
    author="Jamie",
    version="1.0"
)
"Functions are the primary and most important method of code organization and reuse in Python." — Wes McKinney, Python for Data Analysis

How to Use Arguments in a Python Function

Follow these five steps to move from writing a simple function to one that handles any combination of inputs cleanly.

  1. Define the function with parameters

    Use the def keyword followed by the function name and parentheses. Inside the parentheses, list the parameter names separated by commas. For example: def greet(name, greeting):. These parameter names become variables inside the function body that hold whatever values the caller passes in.

  2. Add default values where needed

    Assign a default value to any parameter using an equals sign inside the definition: def greet(name, greeting="Hello"):. Parameters with defaults must be listed after any required parameters. If you place a default parameter before a required one, Python raises a SyntaxError.

  3. Call the function with positional or keyword arguments

    When calling the function, pass values in order (positional) such as greet("Alice", "Hi"), or by name (keyword) such as greet(greeting="Hi", name="Alice"). You can mix both in a single call, but positional arguments must appear before any keyword arguments in that call.

  4. Use *args for a variable number of positional inputs

    Add *args to the parameter list when a function needs to accept any number of values: def total(*numbers):. Inside the function, numbers is a tuple containing every positional argument the caller passed. Iterate over it with a for loop to process each value.

  5. Use **kwargs for a variable number of keyword inputs

    Add **kwargs to the parameter list when a function needs to accept any number of named values: def show_profile(**details):. Inside the function, details is a dictionary where each key is the argument name and each value is what the caller passed. Use details.items() to iterate over all of them.

Python Learning Summary Points

  1. A parameter is the name in the function definition; an argument is the actual value passed when the function is called. Python matches arguments to parameters positionally by default.
  2. Keyword arguments let you pass values by name, making the call order irrelevant and the intent obvious. Default arguments let you skip a parameter entirely — Python fills in the preset value. Defaults must always follow required parameters in the definition.
  3. *args captures any number of extra positional values into a tuple; **kwargs captures any number of extra keyword values into a dictionary. When combining all types, the required order is: positional params, *args, keyword-only params, **kwargs.

Arguments are one of the most used parts of Python. Every time you call a built-in like print(), range(), or sorted(), you are passing arguments. Knowing how each type works — and when to use which — gives you direct control over every function you write or consume.

check your understanding question 1 of 5

Frequently Asked Questions

An argument is a value you pass into a function when you call it. The function uses that value to do its work. Arguments are placed inside the parentheses of a function call — for example, greet('Alice') passes the string 'Alice' as an argument.

A parameter is the variable name listed in the function definition — it acts as a placeholder. An argument is the actual value you supply when calling the function. The parameter receives the argument's value when the function runs.

Positional arguments are values passed to a function in the exact order the parameters were defined. Python matches them left to right. If you have def add(a, b) and call add(3, 5), then a gets 3 and b gets 5 because of their positions.

Keyword arguments are values passed to a function using the parameter name explicitly — for example greet(name='Alice'). Because you name them, the order does not matter. Keyword arguments make function calls more readable and reduce mistakes when a function has many parameters.

A default argument is a parameter that has a pre-set value in the function definition. If the caller does not supply a value for that parameter, Python uses the default. For example, def greet(name='World') uses 'World' if no name is provided.

*args lets a function accept any number of positional arguments. Python collects all extra positional values into a tuple called args. You can iterate over it inside the function. This is useful when you do not know in advance how many values a caller will pass.

**kwargs lets a function accept any number of keyword arguments. Python collects them into a dictionary called kwargs where each key is the parameter name and each value is the supplied value. This is useful for building flexible functions that handle arbitrary named options.

Yes, but positional arguments must always come before keyword arguments in a function call. Python will raise a SyntaxError if you place a keyword argument before a positional one in the same call.

Python raises a TypeError telling you the function received more arguments than it expected — for example: greet() takes 1 positional argument but 2 were given. The fix is to check the function signature and remove the extra argument, or to update the function to accept more parameters.

Default arguments must always come after required (non-default) arguments in the function definition. Writing def greet(name='World', greeting) causes a SyntaxError. The correct order is def greet(greeting, name='World').