Back to all tutorials
pythonfunctionsparameterspython-functions-series

Python Function Parameters and Arguments (Like Ordering Food)

Understand Python function parameters, arguments, default values, and keyword arguments using a simple restaurant-ordering analogy.

The Spark Engineer 2026-08-25 5 min read

Python Function Parameters and Arguments, Explained Like Ordering Food

When you order a pizza, you don't just say "pizza." You say "large pizza, extra cheese, no olives." The restaurant has a base recipe, but your order customizes it. Python function parameters work the same way: they let you customize what a function does each time you call it.

Parameters vs. Arguments

These two words get mixed up constantly, so let's settle it here:

  • A parameter is the placeholder in the function definition, like a blank spot on an order form.
  • An argument is the actual value that you pass to a function when calling it.
Python
def order_pizza(size):   # "size" is the parameter    print(f"Making a {size

f-string (Formatted String Literal)
An f-string in Python is a simple way to put the value of a variable directly inside a string.

  • Without an f-string

    Python
    name = "John"print("Hello, " + name)  # Hello, John
  • With an f-string

    Python
    name = "John"print(f"Hello, {name}")  # Hello, John

Multiple Parameters

Just like a real order form has several fields, a function can take several parameters.

Python
def order_pizza(size, topping):    print(f"Making a {size} pizza with {topping}") order_pizza("large", "extra cheese")

Python here matches the arguments of the parameters by position: "large" goes to size, "extra cheese" goes to topping.

Default Parameter Values

Most restaurants have a default topping if you don't specify any. Python lets you do this with default parameter values.

Python
def order_pizza(size, topping="cheese"):    print(f"Making a {size} pizza with {topping}") order_pizza("medium")                  # uses default: cheeseorder_pizza("medium", "pepperoni")     # overrides default

Defaults make a function flexible without forcing every caller to specify everything.

Keyword Arguments

Instead of relying on order, you can explicitly name each argument, much like filling in labeled fields on an order form instead of in a strict sequence.

PYTHON
order_pizza(topping="mushroom", size="small")

Because each argument is labeled, the order doesn't matter. This is especially useful in functions with many parameters, where remembering the exact position of each one gets error-prone.

Mixing Positional and Keyword Arguments

You can combine both styles, but positional arguments must always come first.

PYTHON
order_pizza("large", topping="olives") # valid order_pizza(topping="olives", "large") # invalid: SyntaxError
  • Positional arguments (e.g. "medium", "pepperoni") — Arguments must be given in the exact sequential order of the parameters.
  • Keyword arguments (e.g. topping="cheeze", size="medium") — Once all positional inputs are satisfied, they can be placed in any order relative to each other.

Required vs. Optional Parameters

A parameter without a default value is required, Python will raise an error if you don't provide it.

def order_pizza(size, topping="cheese"): ... order_pizza() # TypeError: missing required argument 'size'

Think of required parameters as fields that the restaurant can't take an order without, like size, and optional parameters as anything that has a valid default, like toppings.

Putting It Together

Python
def order_pizza(size, topping="cheese", extra_cheese=False):    order = f"{size} pizza with {topping}"    if extra_cheese:        order += " and extra cheese"    return order print(order_pizza("large", "pepperoni", extra_cheese=True))

Here:

  • if extra_cheese: checks whether the customer asked for extra cheese.
  • As we called the function with: extra_cheese=True
  • So the contition is True and hence python runs order += " and extra cheese"
  • Now the order becomes large pizza with pepperoni and extra cheese
  • Finally, return sends the completed order back to whoever called the function.

This single function now handles a wide range of orders without needing a separate function for every combination.

Parameters are like options on an order form. Some options may have default values, while others can be customized when calling a function.

What's Next

Now you know how to customize a function's behavior per call. Next in this series: *args and **kwargs, when you don't know how many toppings someone wants to order.

...
Share

Discussion & Thoughts

Join the conversation with your Google Account

0 Comments

Sign in to leave a comment

We use 1-click Google authentication to prevent bot spam and verify authentic developer discussions.

Loading discussions...