Function Arguments
Learn how to pass values to functions.
We'll cover the following...
Passing arguments to functions
Often, we want our functions to be somewhat flexible, so they don’t do exactly the same thing every time we call them. Consider the following two functions in Python:
Press + to interact
def add_2_and_3():return 2 + 3def add_5_and_9():return 5 + 9
These two functions add two numbers and return the result. The first one adds 2
and 3
, and the second one does the same, but with 5
and 9
. Now, these are just two pairs of numbers. If we would like to have a function that could add any numbers, we would need to create an endless number of functions.
But if we look at what the functions do, we can see that they are actually doing the same thing. They add two numbers and return the ...