Inputs and outputs
Level up your functions! Learn to pass information in with parameters and get results out with return.
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!
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:
A function can return any type of data โ a number, a string, a list, or even another function! Python is very flexible.
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!
Parameters are variables that receive values when the function is called. You put them inside the parentheses when defining the function.
The same function, different results each time!You can have as many parameters as you want โ just separate them with commas!
Click โถ Run to see the output!returnsends a value back to whoever called the function. You can store it in a variable!
Click โถ Run to see the output!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
What does the return statement do in a function?