Python (Fall 2026) Module 7-4: Parameters and Return Values
Watch on YouTube →
Overview
Bill Moseley explains Python functions as black boxes: callers need to know a function’s name, required inputs, and outputs, but not its internal implementation. He demonstrates how a string parameter makes a welcome function reusable, then shows how a two-integer addition function returns a result that can be stored in a variable or passed directly to print().
Key takeaways
- A function’s usable interface consists of its name, required parameters, and return value, allowing callers to use it without understanding its implementation.
- A required parameter must be supplied at the call site; calling the revised doWelcome function with no message produces an error.
- Descriptive parameter names such as strMessage communicate the expected input and make function calls easier to understand.
- Adding a string parameter turns a fixed-message greeting into a reusable function that can display different messages on demand.
- The doAddition function accepts two integer inputs and returns their sum, which can be saved in a variable or printed immediately.
- A returned value can be passed directly into another function call, as with print(doAddition(2, 3)), avoiding a separate result variable.
Chapters
- Moseley compares a function to a black box: users need its name and calling requirements, not its internal code.
- A parameter-free doWelcome() function can print a fixed five-line greeting, but its usefulness is limited to that static message.
- Parameters provide a way to pass information into a function, helping functions work across different programs and scenarios.
- The revised doWelcome function accepts a string parameter named strMessage and uses that variable inside its body.
- Calling doWelcome() without the required argument raises an error; the caller must provide a welcome message such as "This is my program."
- A descriptive parameter name like strMessage helps callers understand what input the function expects, and different messages can be supplied on each call.
- Moseley distinguishes inputs from outputs: parameters carry information into a function, while return values carry information out.
- The doAddition function accepts number1 and number2 as integers, adds them into intAnswer, and returns the sum.
- A call such as doAddition(2, 3) can assign the result to intNumber for later use or be nested inside print() to display it directly.
- Callers only need to know that doAddition takes two integers and returns their sum; its internal steps remain encapsulated.
Transcript excerpt
0:01 using parameters. So parameters, and you're going to hear me say this, but when we create a function, we want to think of it as kind of a black box. You know what I'm talking about when I say black box? Like when an airplane crashes, right? It's got the black box in there. It's the, it's the flight data recorder now. So basically, we don't know what's going on in that flight data recorder, but it has lots of data going into it and the data can come out later on, but we don't, it's a mystery basically what's going on in there. And if we write a good function, if I, if I tell you, hey, guess what? I wrote a, a function that I think is going to be really helpful. It's called doWelcome, and it prints out five lines of code welcoming people to your program. It takes no parameters, and the, the name of it is doWelcome with an uppercase W.
0:56 Now you can use that whenever you want. Do you have to know what the code is inside that function in order to use it? No. All you, all you need to know is what we keep talking about when I show you those function references, is what do I have to put into it to make it work, and that's it. What happens in here doesn't matter. If it works, it works. So when we write functions, that's sort of the gold standard of writing a function as a programmer, especially if you work in a team, because what you want to be able to do is write a function that other people can use. That's, that's what we were looking for. And in order to do that, it has to be able to be used
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Bill Moseley, Ph.D. - Computer Science Educator.