Parameters and returns

Functions become genuinely useful once they can accept input and produce output. In real programs, including those that generate files or coordinate AI-driven workflows, we rarely write functions that operate in isolation. Instead, we pass data in, let the function do focused work, and get a result back that the rest of the program can use.

This lesson introduces how Python functions receive values through parameters and send values back using return values.

Passing values into functions using parameters

Parameters allow us to supply information to a function at the moment we call it. They act as named placeholders for values the function needs in order to do its work.

When we define a function, parameters appear inside the parentheses after the function name.

def page_title(name):
    return f"<h1>{name}</h1>"

When we call the function, we pass an argument that fills in the parameter.

html = page_title("Mars")

Here, the string "Mars" is passed into the function and becomes available as name while the function runs.

Using parameters inside a function body

Inside the function, parameters behave like ordinary variables. We can read them, combine them with other values, or use them to control what the function produces.

def planet_paragraph(name, moons):
    return f"<p>{name} has {moons} known moons.</p>"

The function does not need to know where the values came from. It simply uses the parameters it was given to produce its result.

This keeps the function focused and reusable.

Returning values from functions with return

A return value is how a function sends a result back to the caller. In Python, this is done with the return statement.

def footer():
    return "<footer>Solar System Explorer</footer>"

When Python reaches return, the function finishes executing and hands the value back to whoever called it. The function does not continue running after that point.

Returning values allows functions to participate in larger expressions rather than just performing side effects.

Capturing return values in variables

Most of the time, we store a function’s return value in a variable so we can use it later.

content = planet_paragraph("Jupiter", 95)

The variable now holds the string returned by the function. From there, we might write it to a file, combine it with other HTML fragments, or pass it into another function.

This pattern is common in programs that build structured output step by step.

Using functions as expressions

Because functions return values, we can use them directly inside expressions. We are not limited to assigning their results to variables first.

html = (
    page_title("Saturn")
    + planet_paragraph("Saturn", 146)
    + footer()
)

Here, each function call produces a value, and those values are combined immediately. This makes it easier to see how the final result is assembled.

Functions that return values fit naturally into Python’s expression-based style.

Conclusion

At this point, we are no longer writing isolated blocks of code. By passing values into functions and returning results, we can shape data as it flows through a program. This is the foundation for building larger systems where small, focused functions collaborate to produce meaningful output.

We are now oriented to how functions accept input, produce output, and participate in expressions—skills we will rely on constantly as programs grow.