โ† Back to Python Course
๐Ÿ› ๏ธ Functionsยท25 minยทIntermediate
๐Ÿ“ฅ

Parameters & Returns

Inputs and outputs

Level up your functions! Learn to pass information in with parameters and get results out with return.

๐Ÿ“–

What we are learning

Functions are more powerful when they can receive information (parameters) and send back results (return). Parameters let you customize what a function does, and return lets you use the result elsewhere in your program.

๐Ÿ’ก Think of it like this:

Think of a function like a vending machine. You put in money and select a snack (parameters), the machine does its work, and out comes your snack (return). The machine is reusable โ€” different inputs give different outputs!

๐ŸŒŸ

Why it matters

Parameters and returns turn functions from simple repeaters into flexible, powerful tools. They are the difference between a function that always says "Hello" and one that can greet anyone by name.

Where you see this in real life:

  • โœ“Calculator functions take numbers as parameters and return the result
  • โœ“Game functions take a player name and return their score
  • โœ“Search functions take a query and return matching results
๐ŸŽฏ

By the end, you can:

  • 1.Define functions with parameters
  • 2.Call functions with arguments
  • 3.Use return to send back a result
๐Ÿ”ค

New words

parameterargumentreturnscope
๐Ÿ
If you had a function called "greet" that says hello, what information would you want to pass in? What should it give back?
๐Ÿค“

Fun Fact!

A function can return any type of data โ€” a number, a string, a list, or even another function! Python is very flexible.

๐Ÿ“ฅ Parameters & Returns

Functions are more powerful when they can receive information (parameters) and send back results (return). Parameters let you customize what a function does, and return lets you use the result!

โœจ Functions with Parameters

Parameters are variables that receive values when the function is called. You put them inside the parentheses when defining the function.

๐ŸPass information with parameters
main.py
โ— Output
The same function, different results each time!

๐Ÿ”ข Multiple Parameters

You can have as many parameters as you want โ€” just separate them with commas!

๐ŸMultiple parameters
main.py
โ— Output
Click โ–ถ Run to see the output!

๐Ÿ“ค The return Statement

returnsends a value back to whoever called the function. You can store it in a variable!

๐ŸReturn values with return
main.py
โ— Output
Click โ–ถ Run to see the output!

๐Ÿงช Parameters vs Arguments

Parameter

The variable name in the function definition

def greet(name): โ€” name is a parameter

Argument

The actual value you pass when calling

greet("Alice") โ€” "Alice" is an argument

๐Ÿ
Try this: write a function called 'double' that takes a number and returns it doubled. Then call it with different numbers!
๐Ÿง 

Quick Quiz!

+10 XP

What does the return statement do in a function?

๐Ÿ
Finished the lesson? Click the button to mark it complete and earn XP!