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
You can have more than one parameter, separated by commas:
Python
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
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.
printshows text;returngives you a value to work with.
No comments yet. Add the first comment to start the discussion.