Last modified: Nov 16, 2026

Python Function Arguments Explained

Functions are the building blocks of every Python program. They let you group code and reuse it.

But a function is only as useful as the data you pass into it. That data is called an argument.

Python gives you three main ways to pass arguments: positional, keyword, and default. Each one behaves a little differently.

In this guide, you will learn how all three work. You will see clear examples with real output. By the end, you will know exactly when to use each type.

What Are Function Arguments?

An argument is a value you send to a function when you call it. The function receives it through a parameter.

Parameters are the names inside the function definition. Arguments are the actual values you pass in.

Here is a simple example:


def greet(name):
    print("Hello,", name)

greet("Alice")

Hello, Alice

Here, name is the parameter. The string "Alice" is the argument.

Now let us look at each argument type in detail.

Positional Arguments

Positional arguments are the most common type. You pass values in order, and Python matches them by position.

The first argument goes to the first parameter. The second goes to the second, and so on.


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

describe_pet("dog", "Rex")

I have a dog named Rex.

The order matters a lot. If you swap the values, you get a strange result.


describe_pet("Rex", "dog")

I have a Rex named dog.

Python does not complain. It simply follows the position. So always pass positional arguments in the right order.

If you pass too many or too few arguments, Python raises a TypeError.


describe_pet("dog")

TypeError: describe_pet() missing 1 required positional argument: 'name'

Keyword Arguments

Keyword arguments let you pass values by parameter name. This removes the need to remember the order.

You write the parameter name, an equals sign, and the value.


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

describe_pet(name="Rex", animal="dog")

I have a dog named Rex.

Notice the order changed, but the output is still correct. That is the power of keyword arguments.

They make your code more readable. Anyone reading the call can see what each value means.

You can also mix positional and keyword arguments. Just put positional ones first.


describe_pet("dog", name="Rex")

I have a dog named Rex.

But you cannot put a positional argument after a keyword argument. Python will raise an error.


describe_pet(animal="dog", "Rex")

SyntaxError: positional argument follows keyword argument

Keyword arguments are great when a function has many parameters. They reduce mistakes. If you enjoy clear, readable Python code, you may also like our guide on how to compare a Python set vs list and their key differences.

Default Arguments

Default arguments give a parameter a fallback value. If the caller skips that argument, the default is used.

You set the default in the function definition with an equals sign.


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

greet("Alice")
greet("Bob", "Hi")

Hello, Alice!
Hi, Bob!

In the first call, greeting uses its default. In the second call, you override it.

Default arguments make functions flexible. Callers only provide what they need.

One rule matters here. Parameters with defaults must come after parameters without defaults.


def greet(greeting="Hello", name):
    pass

SyntaxError: non-default argument follows default argument

The Mutable Default Trap

This is a classic beginner mistake. Never use a mutable object like a list or dictionary as a default value.


def add_item(item, basket=[]):
    basket.append(item)
    return basket

print(add_item("apple"))
print(add_item("banana"))

['apple']
['apple', 'banana']

You expected two separate lists. Instead, the same list was reused. Default values are created once, when the function is defined.

The safe fix is to use None as the default.


def add_item(item, basket=None):
    if basket is None:
        basket = []
    basket.append(item)
    return basket

print(add_item("apple"))
print(add_item("banana"))

['apple']
['banana']

Now each call gets a fresh list. This pattern is a must-know for every Python developer.

Dictionaries have similar pitfalls when you misuse them. Our Python dictionary inversion guide shows how to handle dictionary data safely and correctly.

Combining All Three Types

Real functions often use all three argument types together. The order in the definition is fixed.

Positional parameters come first. Then default parameters. Then any keyword-only parameters.


def order_coffee(size, milk="no milk", sugar=0):
    print(f"Size: {size}, Milk: {milk}, Sugar: {sugar}")

order_coffee("large")
order_coffee("small", "oat milk", 2)
order_coffee("medium", sugar=1)

Size: large, Milk: no milk, Sugar: 0
Size: small, Milk: oat milk, Sugar: 2
Size: medium, Milk: no milk, Sugar: 1

Each call uses a different mix. This flexibility is why Python functions stay clean and easy to read.

Best Practices

Follow these tips to keep your functions reliable:

Use positional arguments for short functions with obvious order.

Use keyword arguments when a function has many parameters or when clarity matters.

Use default arguments to make optional settings easy for callers.

Avoid mutable defaults and use None instead.

Keep parameter names short but meaningful. Good names make keyword calls self-documenting.

These habits also help when you work with other data structures. If you ever need to organize dictionary data, our guide on how to sort a Python dict by key is a handy next read.

Conclusion

Python function arguments come in three flavors. Positional arguments rely on order. Keyword arguments rely on names. Default arguments provide fallback values.

Each type solves a different problem. Together, they make your functions flexible and readable.

Start with positional arguments for simple cases. Reach for keyword arguments when clarity matters. Add defaults to make optional settings convenient.

And always watch out for mutable defaults. That one tip will save you hours of debugging.

Practice with the examples above. Try changing the order, adding defaults, and mixing types. The more you experiment, the more natural these concepts will feel.