CH 12 Lesson 2
CH 12 Lesson 2
What are some example functions you have used that required input parameters?
str.format() function to produce a string and the random.randrange() function to generate an integer
How do you de ne and require input parameters in your own function?
Should be identi ed by names that are listed inside the parentheses in the function "def" statement.
These names are called parameters. Ex. def greet (name, town): name and town and parameters 1
and 2.
What happens in you accidentally call a function with positional parameters in the wrong order?
Its up to us as the programmers to ensure that you pass in the required parameters in the correct
order, as de ned by the function.
How do you assign default values to your function parameters?
You can use a default parameter to assign a default value to a parameter in your function de nition.
Default parameter: Function parameters that have a default value that will be used if no input data is
provided.
To de ne default values for parameters in your own function, simply enhance the "def" statement to
set parameters equal to some default value. The example below assigns the default value "Atlanta" to
the town variable in the greet() function.