← Back to Python Course | Chapter 4: Functions | Lesson 2 of 9

Python Function Parameters

What are Parameters and Arguments?

Parameters are the placeholder names listed in a function's definition, while arguments are the actual values supplied when the function is called — the distinction matters because parameters describe the function's interface, arguments fill it in for one specific call.

Example: What are Parameters and Arguments?

python
def greet(name):  # name is the parameter
    print("Hello,", name)

greet("Alex")  # "Alex" is the argument

Positional Arguments

By default, Python matches arguments to parameters by position — the first argument fills the first parameter, and so on — so the order you pass values in a call must line up with the order they were defined.

Example: Positional Arguments

python
def describe(animal, sound):
    print(animal, "says", sound)

describe("Cat", "Meow")

Keyword Arguments

Passing name="value" explicitly by parameter name, instead of relying on position, lets you supply arguments in any order and makes a call self-documenting, since the parameter name is visible right at the call site.

Example: Keyword Arguments

python
def describe(animal, sound):
    print(animal, "says", sound)

describe(sound="Meow", animal="Cat")

Modifying Mutable Parameters

Because lists and dictionaries are mutable, passing one into a function and modifying it inside (like calling .append()) changes the original object the caller still holds — unlike passing a number or string, which can't be altered in place.

Example: Modifying Mutable Parameters

python
def add_item(cart):
    cart.append("apple")

cart = []
add_item(cart)
print(cart)

Positional-Only and Keyword-Only Parameters

A / in the parameter list forces everything before it to be passed positionally, and a * forces everything after it to be passed by keyword only — both are optional safeguards that make a function's calling convention explicit and harder to misuse.

Example: Positional-Only and Keyword-Only Parameters

python
def greet(name, /, *, greeting):
    print(greeting, name)

greet("Alex", greeting="Hi")

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.