Make a PB&J Function

We all know how to make a peanut butter (or almond butter, or cashew butter) sandwich.

But we don’t have to think about all the steps it takes every time, because the steps are already grouped together in our minds as:

"Make a peanut butter and jelly sandwich."

In Python, you might say it something like this:

make_pbj(bread, pb, jam, knife)

What if we wanted to make many different kinds of sandwiches?

"Make a peanut butter and jam sandwich."
"Make a cheese and mustard sandwich."

In Python, that might be expressed as:

make_sandwich(bread, filling, toppings)

In this imaginary function, make_sandwich is the function name, and bread, filling, and toppings are the function's parameters.

make_sandwich(bread, filling, toppings)

^ ^-----^-------^
function name function parameters

Using this function, you could make sandwiches with different types of bread: rye, or sourdough, or whole wheat. Your fillings could be things like bacon, or tofu, or lettuce and tomatoes. And you could use toppings like mustard or mayonnaise.

Because we use variables to represent these parameters, the values can change depending on what kind of sandwich we want!