Introduction to Function Parameters

Introduction: Functions That Adapt

Welcome to the first unit of Passing Data into Python Functions! In the previous course, we learned how to package statements inside a def block and run them whenever we wanted with a simple call. Those functions were useful, but they had one quiet limitation: every call produced exactly the same result because everything the function needed was written directly into its body.

Compare these two headers for a moment:

  • This hard-coded greet() implementation always greets Ada, while greet(name) lets the caller choose the name explicitly.
  • With def greet(name):, each call can pass a different argument — Ada, Grace, Linus, or anyone else we choose.

In this lesson, we will define a function with a single parameter, use that parameter inside the body, and pass different arguments to get different results. This is the first step toward functions that adapt to the data we hand them.

The Problem: Hard-Coded Values Lock a Function In

Let us start with a function that works perfectly well, yet is stuck in place:

Python
def greet():
    print("Hello, Ada!")


greet()

This prints Hello, Ada! every single time, because the name is hard-coded in the body. If we now need to greet Grace, we have only two unpleasant options: edit the string inside the body (which breaks the greeting for Ada), or copy the whole function into a near-identical greet_grace().

That second option should feel familiar. In the previous course, we used functions to remove duplicated statements. Now we face a new flavor of duplication: duplicated definitions that differ by a single value. Parameters are the tool that removes it.

Adding a Parameter to the def Header

The fix is small: we write a name inside the parentheses that we have always left empty.

Python
def greet(name):

Reading this header piece by piece:

  • def still starts the definition, exactly as before.
  • greet is still the function name, in snake_case.
  • The parentheses are now not empty; this is where inputs are declared.
  • name is the parameter: a placeholder label, not a value.
  • The colon still ends the header and opens the indented body.

The important idea is that name currently holds nothing at all. It is a promise that says: "Whoever calls me must hand me one value, and inside the body I will call that value name." Parameters follow the same naming rules as variables, so prefer descriptive snake_case names like name, price, or user_email.

Using the Parameter Inside the Body

Once declared in the header, a parameter behaves inside the body just like any ordinary variable:

Python
# 'name' is a parameter: a placeholder filled in when the function is called
def greet(name):
    print("Hello, " + name + "!")

The body builds one string out of three pieces: the literal text "Hello, ", the value stored in name, and the literal text "!". Notice that name is not wrapped in quotes. Quoted text means "use these exact characters"; an unquoted name means "look up whatever value is stored here." That single difference is what makes the line flexible.

Note: This course often joins text with + concatenation, str(...), or comma-separated print() arguments because f-strings have not been introduced yet. In modern Python, f-strings are a common way to build the same kind of formatted text.

Also notice what is missing: no concrete person appears anywhere in the body. And, as we may recall from previous units, a definition only stores this code; nothing prints yet.

Passing Arguments: Calling the Function with a Value

The value arrives at the call site, inside the parentheses of the call:

Python
greet("Ada")

Python performs three steps here: it evaluates the value "Ada", assigns it to the parameter name, and then runs the body with that assignment in effect. So the print line becomes "Hello, " + "Ada" + "!", giving us:

text
Hello, Ada!

Keep this distinction in mind, since we will use both words constantly: the parameter is the placeholder in the def header, while the argument is the concrete value handed over at the call. Because name is a required parameter with no default, greet must receive exactly one value, either positionally or by keyword. Writing greet() instead raises TypeError: greet() missing 1 required positional argument: 'name'.

The argument Ada flows into the parameter name, which the function body uses to print Hello, Ada!

One Definition, Many Results

Now we can see the real payoff. Here is the complete program: one definition, three calls, and three different arguments.

Python
# 'name' is a parameter: a placeholder filled in when the function is called
def greet(name):
    print("Hello, " + name + "!")


# Each call passes a different argument, producing a different result
greet("Ada")
greet("Grace")
greet("Linus")

Python runs the file from top to bottom: it stores the definition and then executes each call in order. During the first call, name holds "Ada"; during the second, it holds "Grace"; and during the third, it holds "Linus". Thus, the same print line produces three different lines:

text
Hello, Ada!
Hello, Grace!
Hello, Linus!

The body is written once but runs three times, and the output order follows the call order. Greeting a fourth person costs us one new call line, not one new function.

Note: These demos use a flat, unguarded script layout — bare module-level calls with no main() or if __name__ == "__main__": guard. That is a lesson-specific simplification for tiny examples. Larger or importable programs commonly put execution in main() behind a guard; you are not required to implement that pattern here.

Parameters Beyond Strings

Parameters are not limited to text; they can hold numbers, and the body can compute with them rather than just print them:

Python
def print_square(number):
    # The parameter is used twice: in the text and in the calculation
    print("The square of " + str(number) + " is " + str(number * number))


print_square(4)
print_square(7)

Here, number is used inside an arithmetic expression, number * number. One detail matters: + cannot join a number to a string, so we wrap each number in str(...) to convert it to text first. An easier alternative is to pass comma-separated values to print, which handles the conversion for us: print("The square of", number, "is", number * number). Both forms produce this output:

text
The square of 4 is 16
The square of 7 is 49

Conclusion and Next Steps

Let us gather the key points. A parameter is declared inside the parentheses of the def header; it acts like a regular variable inside the body, and its value is supplied by an argument at each call. One definition can therefore serve an unlimited number of inputs, whether those inputs are strings, numbers, or anything else. One last time: parameter is the placeholder in the header; argument is the value passed at the call.

In the exercises ahead, we will read a parameterized function and extend it with new calls, convert a hard-coded greeting into a flexible one, write a numeric single-parameter function from scratch, and build an announce function whose parameter drives several lines of output. After that, the next unit opens the parentheses wider to accept more than one input at a time. Time to put a value in those parentheses and see your functions come alive!

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal