Learn What Parameters Are in Python: Absolute Beginners Tutorial

Parameters are how Python functions receive information. Every time you write a function, parameters are the named slots inside the parentheses that let that function accept data from the outside world. Without them, a function can only ever do the same exact thing every time it runs. With them, one function can handle dozens of different situations.

Python draws a clear line between the variable name you define in a function and the value you hand in when calling it. Getting that distinction right early on prevents a lot of confusion. This tutorial works through each parameter type from the simplest case to the more flexible forms, with interactive challenges along the way to reinforce what you read.

Parameters vs. Arguments: The Key Distinction

When you write a function definition in Python, the names inside the parentheses are called parameters. When you actually call that function and pass in values, those values are called arguments. The two terms are not interchangeable even though people mix them up constantly.

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

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

Think of a parameter as a labeled box on a form. The form itself (the function definition) describes what kind of information goes in that box. The argument is the actual thing you write in the box when you fill the form out.

Note

Python documentation uses "parameter" for the definition side and "argument" for the call side. The official term for what you pass at call time is also sometimes written as "actual argument," while what is defined in the signature is called a "formal parameter." For everyday code discussions, most developers just say "param" and "arg."

A function with no parameters looks like this. The parentheses are still required — they are just empty.

python
def say_hello():
    print("Hello, world!")

say_hello()   # Output: Hello, world!

A function with multiple parameters separates each name with a comma. When you call the function, you provide one argument for each parameter, in the same order they are listed.

python
def add(x, y):
    return x + y

result = add(3, 5)
print(result)   # Output: 8
Pro Tip

Inside the function body, a parameter behaves exactly like a regular variable. You can read it, pass it to other functions, perform calculations on it, or return it — just like any other name in that scope.

code builder click a token to place it

Build a function that takes a single parameter called username and prints a welcome message:

your code will appear here...
username return welcome( def : print )
Why: A function definition starts with def, then the function name followed immediately by an opening parenthesis, then the parameter name, a closing parenthesis, and finally a colon. The colon signals the start of the function body. return and print belong inside the body, not in the signature.

Positional and Default Parameters

There are several ways to define and pass parameters. The most fundamental are positional parameters, where order determines which value goes to which name. Build on those with default parameters, which give a parameter a fallback value so it becomes optional when calling the function.

Positional Parameters

With positional parameters, Python assigns values left to right, matching the first argument to the first parameter, the second argument to the second parameter, and so on. If the order is wrong, the behavior will be wrong — Python does not detect this for you automatically.

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

describe_pet("cat", "Mochi")    # I have a cat named Mochi.
describe_pet("Mochi", "cat")    # I have a Mochi named cat. (wrong order!)

Default Parameters

A default parameter has a value pre-assigned in the function definition. If the caller does not supply an argument for it, Python uses the default. If the caller does supply a value, that value overrides the default.

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

greet("Alice")              # Hello, Alice!
greet("Bob", "Good morning")  # Good morning, Bob!
Important Rule

Default parameters must always come after parameters without defaults. Writing def greet(greeting="Hello", name): causes a SyntaxError. Python enforces this order because if a parameter with a default appeared first, Python would have no reliable way to know which argument matched which parameter.

A common mistake is using a mutable object such as a list as a default value. That default is created once and shared across all calls, which leads to surprising behavior.

python
# Dangerous — the list default is shared across all calls
def add_item(item, items=[]):
    items.append(item)
    return items

print(add_item("apple"))   # ['apple']
print(add_item("banana"))  # ['apple', 'banana'] -- not what you expected!

# Safe — use None as the default and create a new list inside
def add_item_safe(item, items=None):
    if items is None:
        items = []
    items.append(item)
    return items
Syntax
def fn(x):
Required?
Yes — caller must provide a value or Python raises TypeError.
Syntax
def fn(x, y=10):
Required?
No — if the caller omits it, Python uses the preset default value.
Syntax
def fn(*args):
Required?
No — collects zero or more extra positional arguments into a tuple called args.
Syntax
def fn(**kwargs):
Required?
No — collects zero or more extra keyword arguments into a dictionary called kwargs.
spot the bug click the line that contains the bug

This function should greet a user with an optional custom message. One line contains a syntax error. Click it, then hit check.

1 def greet(message="Hi", name):
2 print(message + ", " + name + "!")
3
4 greet("Alice")
The fix: Change def greet(message="Hi", name): to def greet(name, message="Hi"):. Parameters without default values must come before parameters that have defaults. Python raises a SyntaxError when a non-default parameter follows a default parameter because the positional assignment would become ambiguous.

Keyword Arguments and Parameter Types at a Glance

A keyword argument is not a new kind of parameter — it is a way of passing an argument at call time by naming the parameter you want it to bind to. This lets you pass arguments in any order and makes call sites more self-documenting.

python
def register(username, email, role="member"):
    print(f"Registering {username} ({email}) as {role}")

# Positional
register("alice", "alice@example.com")

# Keyword — order no longer matters
register(email="bob@example.com", username="bob", role="admin")

*args: Accepting Any Number of Positional Arguments

When you do not know in advance how many positional values a function will receive, use *args. The single asterisk tells Python to collect all remaining positional arguments into a tuple. The name args is a convention — the asterisk is what matters.

python
def total(*args):
    return sum(args)

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

# Inside the function, args is a tuple
def show_items(*args):
    for item in args:
        print(item)

**kwargs: Accepting Any Number of Keyword Arguments

The double-asterisk syntax collects extra keyword arguments into a dictionary. Each key is the argument name the caller used, and each value is the corresponding value passed.

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

show_info(name="Alice", age=30, city="Austin")
# name: Alice
# age: 30
# city: Austin

You can combine all of these in a single function definition. When you do, they must appear in a specific order: regular positional parameters first, then *args, then keyword-only parameters, then **kwargs last.

python
def full_example(a, b, *args, label="default", **kwargs):
    print("a:", a)
    print("b:", b)
    print("extra positional:", args)
    print("label:", label)
    print("extra keyword:", kwargs)

full_example(1, 2, 3, 4, label="test", x=10, y=20)
# a: 1
# b: 2
# extra positional: (3, 4)
# label: test
# extra keyword: {'x': 10, 'y': 20}
def compute(x, y=0, *args, **kwargs): keyword function name positional default param *args **kwargs
Anatomy of a Python function definition — the location and role of each parameter type.
"Arguments are said to be passed to a function; parameters are local variables." — Python Documentation

How to Define and Use Parameters in Python

These steps build one skill on top of the next, taking you from a bare function definition to a flexible one that handles any number of inputs.

  1. Write the def keyword and function name

    Start with def followed by a descriptive name for your function. The name should reflect what the function does. End it with an opening parenthesis: def calculate(

  2. List parameter names inside the parentheses

    Write each parameter name separated by commas. Use names that describe the data they will hold. Close the parentheses and add a colon: def calculate(price, tax_rate):

  3. Add default values where appropriate

    Assign a default to any parameter that has a sensible fallback. Remember: parameters with defaults must follow parameters without them. Example: def calculate(price, tax_rate=0.08):

  4. Use *args or **kwargs for flexible input

    If the number of inputs is unknown at the time of writing, add *args after your fixed parameters to collect extra positional values as a tuple, or add **kwargs after *args to collect extra named values as a dictionary.

  5. Call the function with the appropriate arguments

    Pass values by position, by keyword, or both. When mixing, positional arguments must come before keyword arguments in the call. For example: calculate(49.99) or calculate(price=49.99, tax_rate=0.1).

Python Learning Summary Points

  1. A parameter is a name in the function definition; an argument is the value passed when calling the function. The two words describe the same slot from different angles.
  2. Positional parameters depend on order. Default parameters have fallback values and must appear after positional ones. Passing too many or too few required arguments raises a TypeError.
  3. *args collects extra positional arguments into a tuple; **kwargs collects extra keyword arguments into a dictionary. Both are optional and consume any leftover values not matched by earlier parameters.
  4. When combining parameter types, the required order is: positional, default, *args, keyword-only, **kwargs. Python enforces this order with a SyntaxError if violated.
  5. Never use a mutable object such as a list or dictionary as a default parameter value. Use None as the default and create the mutable inside the function body instead.

Parameters are one of the most frequently used tools in any Python program. Understanding how they behave — especially how defaults, *args, and **kwargs interact — gives you a solid foundation for writing functions that are flexible, readable, and easy to call correctly. The interactive challenges above mirror the kind of thinking that becomes automatic with practice.

check your understanding question 1 of 5

Frequently Asked Questions

A parameter is a variable name listed inside the parentheses of a function definition. It acts as a placeholder that receives a value when the function is called. For example, in def greet(name):, the word name is a parameter.

A parameter is defined in the function signature and acts as a local variable inside the function. An argument is the actual value you pass when calling the function. In def add(x, y):, x and y are parameters. In add(3, 5), the values 3 and 5 are arguments.

A positional parameter receives its value based on the position it appears in the function call. The first argument goes to the first parameter, the second argument to the second parameter, and so on. Order matters with positional parameters.

A default parameter has a preset value that Python uses when no argument is provided for it during the function call. You define it with an equals sign in the function signature, such as def greet(name, greeting='Hello'):. Parameters with defaults must come after parameters without defaults.

A keyword argument is passed to a function by explicitly naming the parameter it should bind to. For example, greet(name='Alice') passes 'Alice' as a keyword argument. This lets you pass arguments in any order and makes function calls more readable.

*args lets a function accept any number of positional arguments. Inside the function, args is a tuple containing all the extra positional values passed. The asterisk is the syntax; the name args is a convention, not a requirement.

**kwargs lets a function accept any number of keyword arguments. Inside the function, kwargs is a dictionary where keys are the argument names and values are the corresponding values passed. It is commonly used when the function needs to forward named options to another function.

Python raises a TypeError at runtime, reporting that the function received more positional arguments than it accepts. A function defined with two parameters will fail if you call it with three arguments unless it uses *args.

Yes. A function defined as def say_hello(): has no parameters and takes no arguments when called. It simply runs its body every time it is called without needing any input.

The correct order is: positional parameters first, then default parameters, then *args, then keyword-only parameters, and finally **kwargs. Python enforces this order and raises a SyntaxError if it is violated.