Level 1
0 / 100 XP

Parameters and return

Functions get really useful when you can feed them data and get an answer back. That's what parameters and return are for.

Parameters: passing data in

List parameters inside the parentheses. They act like variables the caller fills in:

Python
def greet(name): print("Hello, " + name) greet("Alice") # Hello, Alice greet("Sam") # Hello, Sam

You can have more than one parameter, separated by commas:

Python
def add(a, b): print(a + b) add(2, 3) # 5

return: sending a value back

print only shows text on screen. To send a value back to the caller so it can be reused, use return:

Python
def add(a, b): return a + b result = add(2, 3) print(result) # 5 print(add(10, 5)) # 15

The difference matters: a function that prints just displays something, while a function that returns hands you a value you can store, print, or use in more math.

Key takeaways

  • Parameters go in the parentheses and let the caller pass data in.
  • return sends a value back so the caller can use the result.
  • print shows text; return gives you a value to work with.