This keyword begins every user-defined function in Python
def
This built-in function returns the absolute value of a number
abs()
Is the following function defined with arguments or without?
def area_rectangle():
Without arguments (no parameters listed)
What Python keyword is used to send a value back from a function to the caller?
return
Name the three steps required to call a function
name, add parentheses (), include any required parameters inside parentheses separated by commas
Which built-in function would you use to get the sum of numbers in a list?
sum()
If a function has two parameters, what must you do when you call it?
Call it with exactly two arguments (neither less nor more)
Given this function, what will calling
rect_area = area_rectangle(3, 4) store in rect_area?
def area_rectangle(l, w):
area = l * w
return area
12
True or False: A function’s code runs automatically when Python reads the program
False — functions run only when they are called
returns either True or False based on the parameter passed.
bool()
The values you pass into a function when calling it are called _______
arguments
Why might we prefer a function that returns a value to one that only prints the result? Give one clear reason
A function that returns a value allows you to reuse the result in other parts of your program
Write the short one-line purpose of a user-defined function in your own words
A user-defined function packages code to perform a specific task so we can reuse it
The built-in function ____ sorts list elements in place
sort()
Given this definition, how many parameters are there and what are their names?
def area_rectangle(l, w):
return l * w
Two parameters:
l and w
Read this function and say what value it returns when called as double_number(10).
def double_number(n):
return n * 2
returns 20
Given the function definition below, what is the name of the function and does it take any parameters? def greet(): print("Welcome!")
Name: greet; Parameters: none (no arguments)
Which built-in function returns the result of raising a number to a power (base and exponent)?
pow()
Explain one advantage of passing values as arguments into a function instead of asking for input inside the function.
It makes the function reusable for many inputs and separates input gathering from logic so the function can be tested more easily.
Write a short function definition named add_three that accepts one parameter x and returns x plus 3
write the code
def add_three(x):
return x + 3